繁体   English   中英

如何停止jQuery旋转动画?

[英]How to stop a jQuery rotate animation?

我正在基于jplayer插件开发音频多媒体播放器(转盘),并且在div上使用了rotate属性:

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

首先,当用户单击另一个div时,我想停止旋转。

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

非常感谢你。

设置setInterval等于var是一件好事:

var timer = setInterval(...)

那么您可以通过以下方式停止它:

clearInterval(timer)

然后停止动画,请执行以下操作:

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

给超时一个变量!

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

以及何时需要停止它:

clearTimeout( timer );

setInterval返回一个值。 存储它,然后使用该变量作为参数调用clearInterval

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

clearInterval将停止函数的常规执行

如果可能,我搜索一个函数,该函数返回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();
    }
}

再次感谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM