2012-03-01 31 views
1

我需要能够每8秒钟在我的网页中的五个不同的html片段之间进行旋转。在页面上旋转html的最佳方式

这样做的最好方法是什么? JQuery或本地JS很好。

+1

有什么内容?你想如何旋转它? – ori 2012-03-01 19:55:27

+0

由显示和隐藏的5个divs – cdub 2012-03-01 19:56:11

回答

1

确实有很多插件。

但在这里,如果你想自己做,你可以使用一些基本结构:

// assuming all your divs have the class `rotating-content`: 

$(document).ready(function() { 
    var divs = $('.rotating-content').hide(); 
    var curr_div = divs.first().show();   

    function nextcontent() { 
     // hide current div, then move the next one or the first div, and show it 
     curr_div = curr_div.hide().next().add(divs.first()).first().show(); 
     setTimeout(nextcontent, 5000); // 5 seconds 
    } 
    setTimeout(nextcontent, 5000); 
}); 
0

你的意思是像幻灯片?您可以使用jQuery Cycle插件从malsup,

这里有一个例子:http://jsfiddle.net/JKirchartz/zLekb/(没有这额外的东西是必要的,这只是一个例子,我已经回收)

如果你想改变每8秒将timeout更改为8000(以毫秒为单位)

相关问题