Reputation: 324
Currently I'm trying to make some sort of vertical auto-scrolling. This is my code
$(document).ready(function() {
var reachEnd = false;
var top = 0;
function animateMargin(){
if(top == -720){
reachEnd = true;
}
if(reachEnd == false){
$('#bslider').animate({'marginTop' : '-=240px'}, 500);
top -=240;
}else{
$('#bslider').animate({'marginTop' : '0px'}, 1000);
top = 0;
reachEnd = false;
}
};
marginInterval = setInterval('animateMargin()', 5000);
$('#banner').hover(function(){
clearInterval( marginInterval );
},
function(){
marginInterval = setInterval('animateMargin()', 5000);
});
});
And it's not working - at all.
Any ideas?
Upvotes: 0
Views: 3455
Reputation: 9298
setInterval()
takes an callback function.
Passing animateMargin()
with (), you have passed in the result of the function call, which is the return value of the function.
Instead, you should pass in the function itself as animateMargin
Upvotes: 1
Reputation: 4514
You seem to be passing the function
callback to setInterval
incorrectly. Try this instead.
setInterval( animateMargin, 5000 );
Upvotes: 2