Jquery旋转:停止无限旋转

时间:2013-03-06 02:36:05

标签: jquery

我正在使用此插件http://code.google.com/p/jqueryrotate/

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

我想在点击#img时停止旋转,但这不起作用。

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

有没有办法停止setInterval?

1 个答案:

答案 0 :(得分:3)

如果您将setInterval来电存储在变量中,则可以在其上调用clearInterval来阻止它。

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
});