user742736
user742736

Reputation: 2729

Jquery rotate: stop endless rotation

I'm using this plugin http://code.google.com/p/jqueryrotate/

var angle = 0;
setInterval(function(){
  angle+=3;
 $("#img").rotate(angle);
},50)

I would like to stop the rotation when I click on #img but that doesn't work.

$("#img").stopRotate();

Is there a way to stop the setInterval?

Upvotes: 0

Views: 1624

Answers (1)

Elliot Bonneville
Elliot Bonneville

Reputation: 53301

If you store your setInterval call in a variable, you can then call clearInterval on it which will stop it.

var angle = 0;
var interval = setInterval(function(){
    angle+=3;
    $("#img").rotate(angle);
},50)

$("#img").click(function() {
    clearInterval(interval); // stick the clearInterval in a click event
});

Upvotes: 3

Related Questions