jQuery rotate/transform

前端 未结 5 1292
无人共我
无人共我 2020-12-13 10:10

I\'d like to use this function to rotate then stop at a particular point or degree. Right now the element just rotates without stopping. Here\'s the code:

           


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 10:44

    Why not just use, toggleClass on click?

    js:

    $(this).toggleClass("up");
    

    css:

    button.up {
        -webkit-transform: rotate(180deg);
           -moz-transform: rotate(180deg);
            -ms-transform: rotate(180deg);
             -o-transform: rotate(180deg);
                transform: rotate(180deg);
                   /* IE6–IE9 */
                   filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.9914448613738104, M12=-0.13052619222005157,M21=0.13052619222005157, M22=0.9914448613738104, sizingMethod='auto expand');
                     zoom: 1;
        }
    

    you can also add this to the css:

    button{
            -webkit-transition: all 500ms ease-in-out;
            -moz-transition: all 500ms ease-in-out;
            -o-transition: all 500ms ease-in-out;
            -ms-transition: all 500ms ease-in-out;
    }
    

    which will add the animation.

    PS...

    to answer your original question:

    you said that it rotates but never stops. When using set timeout you need to make sure you have a condition that will not call settimeout or else it will run forever. So for your code:

    
    

提交回复
热议问题