2011-03-17 131 views
2

我工作的一个音频多媒体播放器基于jplayer插件(转盘),和我使用一个div的旋转特性:如何停止jQuery旋转动画?

setInterval( 
    function() { 
     $('#plateau').animate({ 
      rotate: '+=4deg' 
     }, 0); 
    }, 
    3); 

首先,我想,当用户停止了转动点击另一个div。

其次,我想停止旋转最大程度的限制。

非常感谢。

+2

不要担心'糟糕的英语',你的问题是清晰的,写得很好,即使你是英语母语的人也会这样。但是,我确实修改了您的问题标题,以反映问题*和*以消除“呐喊”。 – 2011-03-17 20:14:47

+0

使用此链接 http://stackoverflow.com/questions/2803820/how-do-i-build-a-specialized-jquery-timer/7291411#7291411 – Prasanth 2011-09-03 05:53:40

回答

1

给超时一个var!

var timer = setTimeout(function(){ ... }, 0); 

,当你需要停止它:

clearTimeout(timer); 
+0

非常感谢您 – 2011-03-18 13:01:56

+0

你是最欢迎。如果有帮助,您可以评价我的答案,因为它有用:) – 2011-03-18 16:03:43

5

很好的一件事设定的setInterval等于VAR:

var timer = setInterval(...) 

比你可以阻止它

clearInterval(timer) 

然后停止动画做:

$('#plateau').stop(); 
+0

非常感谢, – 2011-03-17 21:12:37

+0

没有概率鲍勃:-)一个10亿亿美元的支票将是很好的:-D – Neal 2011-03-17 21:24:02

+0

或'正确答案'检查! ;) – 2011-03-24 20:57:45

0

setInterval正在返回一个值。储存,然后调用clearInterval这个变量作为参数

toto = setInterval(function(){…}) 
… 
clearInterval(toto) 

clearInterval将停止功能的正常执行

0

如果有可能,我寻找谁返回程度的实际位置的功能DIV,对于可以同步手臂的运动与像一个真正的转盘播放器的实际播放位置:再次

function rotation_bras(bras_rotation) 
{ 
    /*var temps_actuel = $.jPlayer.convertTime(tt);*/ // Send the total time of the track 
    // Begin position in degree 17deg 
    // Maximum position in degree 40 deg 
    // When a track is finish, the arm's turntable comeback at the initial position 
    // The degree decalage should be depend to the total time of the track 
    if(bras_rotation==true) 
    { 
     BrasTourne = setInterval(function(){$('#bras').animate({rotate: '+=0.1deg'}, 0);}); 
    } 
    else { 
     clearInterval(BrasTourne); 
     $('#bras').stop(); 
    } 
} 

感谢

+0

这是一个答案?还是继续你自己的问题? – Neal 2011-03-24 21:02:12