2010-02-26 126 views
2

我的網頁上有五個div(#art #fashion,#self,#nightlife,#community)。 現在,當您將鼠標懸停在它們上面時,它們會將頁面內容加載到另一個容器div(#flyer)中。通過jquery循環顯示圖片

我希望傳單內容每5秒循環一次。

所以,而不必鼠標懸停這5個div,它應該自動去。

確實有道理嗎?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script> 

<script type="text/javascript"> 
$(document).ready(function() { 
     $("#art").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
     $("#fashion").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
     $("#self").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
     $("#nightlife").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
     $("#community").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
}); 
</script> 

回答

2

我喜歡使用jquery週期(http://malsup.com/jquery/cycle/)的組合用於一些附加動畫效果循環內容和jQuery緩解(http://gsgd.co.uk/sandbox/jquery/easing/)來完成此

+0

我覺得有一個「循環」插件,但我該如何去執行它?顯然,我的jquery技能是有限的。 此外,我忘了提及每個傳單鏈接到一個不同的頁面。 所以當它通過每個傳單循環時,鏈接仍然應該是活動的。 – Pico 2010-02-26 19:41:26

+0

我想我應該明確一點,我需要循環DIV而不僅僅是圖像。致歉,請致電 。 – Pico 2010-02-26 19:46:25

3

另一種方式是使用setInterval函數像這樣...

$(document).ready(function() { 
    var sourceElements = $("#art,#fashion,#self,#nightlife,#community"); 
    var pointer = 0; 
    setInterval(function() { 
     $('#flyer').load($(sourceElements[pointer++]).attr("href") + ' #flyer'); 
     if (!sourceElements[pointer]) pointer = 0; 
    , 5000}); 
}); 
+1

非常好的酵素:] – 2010-02-26 21:55:46