我正在开发基于jplayer插件的音频多媒体播放器(转盘),我正在使用div上的rotate属性:
setInterval(
function () {
$('#plateau').animate({
rotate: '+=4deg'
}, 0);
},
3);
首先,我想在用户点击另一个div时停止轮换。
其次,我想在最大程度限制下停止旋转。
非常感谢。
答案 0 :(得分:5)
一件事情,设置setInterval等于var:
var timer = setInterval(...)
比你可以用:
来阻止它clearInterval(timer)
然后停止动画做:
$('#plateau').stop();
答案 1 :(得分:1)
给超时一个变量!
var timer = setTimeout(function(){ ... }, 0);
当你需要阻止它时:
clearTimeout( timer );
答案 2 :(得分:0)
setInterval
正在返回一个值。存储它,然后使用此变量作为参数
clearInterval
toto = setInterval(function(){…})
…
clearInterval(toto)
clearInterval
将停止定期执行函数
答案 3 :(得分: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();
}
}
再次感谢