开发者

Jquery twitter ticker first li 2 times

开发者 https://www.devze.com 2023-03-20 18:13 出处:网络
Hello Stackoverflow users, I hav开发者_JS百科e created a tweet ticker with jquery for a website. The problem now is that the first tweet is showing 2 times and when that is over it is working great.

Hello Stackoverflow users,

I hav开发者_JS百科e created a tweet ticker with jquery for a website. The problem now is that the first tweet is showing 2 times and when that is over it is working great.

But how can i make it so that the first tweet is only shows one time and not 2 times.

I have made a Fiddle so you can see what is going wrong: JSFiddle link


Your problem seems to be occcuring because the code is executing the following two lines, before it has downloaded all the data from Twitter -

var ticker = $('.tweets ul');
ticker.children('li:first').show().siblings().hide();

The solution below should solve the problem.

$(document).ready(function() {
$(".tweets").tweet({
    count: 20,
    template: "{user}: {text}",
    username: "VersioISP",
    favorites: true
}).bind("loaded", function() {
    $(this).find("a").attr("target", "_blank");
    var ticker = $('.tweets ul');
    ticker.children('li:first').show().siblings().hide();
});

var ticker = $('.tweets ul');

setInterval(function() {
    ticker.find('li:visible').fadeOut(function() {
        $(this).appendTo(ticker);
        ticker.children('li:first').show();
    });
}, 2000);
})
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号