3 回答

TA贡献1864条经验 获得超6个赞
每10秒循环一次div。
$(function () {
var counter = 0,
divs = $('#div1, #div2, #div3');
function showDiv () {
divs.hide() // hide all divs
.filter(function (index) { return index == counter % 3; }) // figure out correct div to show
.show('fast'); // and show it
counter++;
}; // function to loop through divs and show correct div
showDiv(); // show first div
setInterval(function () {
showDiv(); // show next div
}, 10 * 1000); // do this every 10 seconds
});

TA贡献1802条经验 获得超5个赞
这是我提出的jQuery插件:
$.fn.cycle = function(timeout){
var $all_elem = $(this)
show_cycle_elem = function(index){
if(index == $all_elem.length) return; //you can make it start-over, if you want
$all_elem.hide().eq(index).fadeIn()
setTimeout(function(){show_cycle_elem(++index)}, timeout);
}
show_cycle_elem(0);
}
您需要为所有要循环的div设置一个公共类名,使用它如下:
$("div.cycleme").cycle(5000)
添加回答
举报