2010-07-30 84 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

干得好克里斯。工作绝对美味。