我正在使用此插件http://code.google.com/p/jqueryrotate/
var angle = 0;
setInterval(function(){
angle+=3;
$("#img").rotate(angle);
},50)
我想在点击#img时停止旋转,但这不起作用。
$("#img").stopRotate();
有没有办法停止setInterval?
答案 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
});