I have some problem with this code, when I click the start button everything is working as expected but when I want to stop animation with clearInterval it doesn’t work, just keeps looping… What I am doing wrong?
var a = function() {
$("div").animate({height:300},"slow");
$("div").animate({width:300},"slow");
$("div").animate({height:100},"slow");
$("div").animate({width:100},"slow");
}
$(document).ready(function(){
$("start").click(function(){
setInterval(a,1000);
});
$("stop").click(function(){
clearInterval(a);
});
});
You should pass a reference(which you get from
setInterval) toclearIntervalmethod to clear it. Try this