Reputation: 3853
I'm creating a horizontal ticker to scroll latest tweet. Feeding in tweets via Sea of clouds jQuery plugin.
I have created an animation function which I'm trying to loop using a setTimeout(doTicker, 6000);
Can anyone help me see what I'm doing wrong? Help much appreciated thanks.
See code below...
Have also created fiddle. http://jsfiddle.net/motocomdigital/h4x8D/1/
Can't get the doTicker to loop/cycle
$(".tweetbar-ticker").tweet({
username: "twitter",
join_text: "auto",
count: 1,
auto_join_text_default: "we said,",
auto_join_text_ed: "we",
auto_join_text_ing: "we were",
auto_join_text_reply: "we replied to",
auto_join_text_url: "we were checking out",
loading_text: "loading tweets..."
}).bind("loaded", function() {
$('.tweetbar-ticker ul li').clone().appendTo('.tweetbar-ticker ul');
var $tweetBar = $('.tweetbar-ticker'),
tweetLength = $('.tweetbar-ticker ul li').outerWidth(),
$tweetAnchor = $('.tweetbar-ticker ul li a');
$tweetBar.css({
'width': tweetLength * 2 + 'px'
});
$tweetAnchor.attr({
target: "_blank"
});
function doTicker() {
$tweetBar.animate({
'left': '-' + tweetLength + 'px'
}, 20000, 'linear');
setTimeout(doTicker, 6000);
}
doTicker();
});
Thanks Josh
Upvotes: 0
Views: 782
Reputation: 1524
You have correct code, but it wont animate -left as soon as it is allready animated to that value, so you have to reset left css.
Second, it's better to call it as callback not as setTimeout...
check that:
Upvotes: 2
Reputation: 21830
are you trying to call doTicker() recursively with a 6 second timeout?
if so, why not use setInterval
instead?
that would be this:
function doTicker() {
$tweetBar.animate({
'left': '-' + tweetLength + 'px'
}, 20000, 'linear');
}
setInterval(doTicker,6000);
Upvotes: 0