Javascript Ticker Problem
I found a bit of Javascript to create a news ticker—essentially just rotating through the items of a list.
<script>
var ticker = $('ul.ticker');
ticker.children(':first').show().siblings().hide();
setInterval(function() {
ticker.find(':开发者_运维问答visible').fadeOut(function() {
$(this).appendTo(ticker);
ticker.children(':first').show();
});
},5000);
</script>
It worked really well when I just had list items, but when I made the list items into links it started acting strangely. I watched it with firebug and it appears that it goes through the list just fine the first time, then starts creating new list items:
<li style="display: none;"></li>
It seems to alternate displaying one of these <li>
then after it goes through the list the first time.
Thank you for your help!
edit 1: HTML
<ul class="ticker">
<li><a href="#">News Item</a></li>
<li><a href="#">News Item 2</a></li>
</ul>
I think, that problem lies in ticker.find(':visible')
. If your links are wrapped in li
, then that code finds li
and a
inside of it and appending them separately to the ticker. Try ticker.find('li:visible')
.
EDIT: or ticker.children(':visible')
.
精彩评论