admin管理员组

文章数量:1406063

I'm working on a audio multimedia player (turntable) based on jplayer plugin, and I'm using the rotate property on a div :

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

Firstly, I would like to stop the rotation when a user clicks on another div.

Secondly, I would like to stop the rotation whith a maximum degree limitation.

Thank you very much.

I'm working on a audio multimedia player (turntable) based on jplayer plugin, and I'm using the rotate property on a div :

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

Firstly, I would like to stop the rotation when a user clicks on another div.

Secondly, I would like to stop the rotation whith a maximum degree limitation.

Thank you very much.

Share Improve this question edited Oct 24, 2012 at 13:15 Tisho 8,5026 gold badges45 silver badges52 bronze badges asked Mar 17, 2011 at 20:11 Gabriel BGabriel B 211 silver badge2 bronze badges 2
  • 2 Don't worry about the 'bad English,' your question is clear and well written, and would be so even if you were a native English-speaker. I did, however, amend your question title to reflect the question and to remove the 'shouting.' – David Thomas Commented Mar 17, 2011 at 20:14
  • Use this link stackoverflow./questions/2803820/… – Prasanth Commented Sep 3, 2011 at 5:53
Add a ment  | 

4 Answers 4

Reset to default 5

well for one thing set setInterval equal to a var:

var timer = setInterval(...)

than you can stop it with:

clearInterval(timer)

and then to stop the animation do:

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

Give the timeout a var!

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

and when you need to stop it:

clearTimeout( timer );

setInterval is returning a value. Store it, and then call clearInterval with this variable as a parameter

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

clearInterval will stop the regular execution of the function

If it's possible, I search a function who return the actual position in degree of the div, for can sync the movement of the arm with the actual playing position like on a real turntable player :

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

Thanks again

本文标签: javascriptHow to stop a jQuery rotate animationStack Overflow