2012-03-01 29 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(以毫秒爲單位)

相關問題