2010-07-30 126 views
1

我使用天氣饋送來顯示頁面上的天氣。我想以5秒的間隔在2個或更多的天氣位置循環。通過遠程JavaScripts循環創建多個天氣饋線

我以爲我可以適應像這樣How can I cycle through pages?,但沒有任何運氣。

的源代碼爲3如下供稿我想持續循環通過在間隔:預先

<script type="text/javascript" src="http://www.weatherzone.com.au/woys/graphic_current.jsp?postcode=3000"></script> 

<script type="text/javascript" src="http://www.weatherzone.com.au/woys/graphic_current.jsp?postcode=3690"></script> 

<script type="text/javascript" src="http://www.weatherzone.com.au/woys/graphic_current.jsp?postcode=2000"></script> 

感謝。

回答

0

由於這些小部件使用document.write()的,我只想輸出的所有3到頁面開始,在一個無序列表,也許,只是循環顯示隱藏他們。

因此,使用類似這樣的標記:

<ul id="cycle"> 
    <li><script type="text/javascript" src="http://www.weatherzone.com.au/woys/graphic_current.jsp?postcode=3000"></script></li> 
    <li><script type="text/javascript" src="http://www.weatherzone.com.au/woys/graphic_current.jsp?postcode=3690"></script></li> 
    <li><script type="text/javascript" src="http://www.weatherzone.com.au/woys/graphic_current.jsp?postcode=2000"></script></li> 
</ul> 

你可以使用jQuery做這樣的事情:

jQuery(function($) { 

    var items = $('#cycle li'), // elements to be cycled through 
     interval = 2000,  // time between cycles 
     i = 0; 

    // hides all the elements, except the first one 
    items.not(":first").each(function() {$(this).hide()}) 

    // show, hide elements every "interval" milliseconds 
    window.setInterval(function() { 
     $(items[ (i==0) ? (items.length - i) - 1 : i - 1 ]).hide() 
     $(items[i++]).show(); 
     if (!items[i]) i = 0; 
    }, interval); 

}); 
0

幹得好克里斯。工作絕對美味。