简体   繁体   English

如何旋转然后停止?

[英]How to make a rotation and then stop?

I got a div to start rotating, but I am not sure how to make it stop at an angle.我有一个 div 开始旋转,但我不确定如何让它停止在一个角度。 At the moment all that is happing is that it keeps going.目前,所有令人高兴的事情都在继续进行。 My question is how do i get it to stop at an angle like 96.我的问题是如何让它停止在像 96 这样的角度。

<script type="text/javascript">
$(function() {
var $elie = $("#super");
rotate(1);
function rotate(degree) {        
    $elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});  
    $elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});                      
    timer = setTimeout(function() {
     rotate(++degree);
    },2);
}
});
</script>

To stop at 96 degress, try this:要停在 96 度,试试这个:

if (degree < 96) {
    timer = setTimeout(function() {
        rotate(++degree);
    }, 2);
}

Example fiddle示例小提琴

Try something like this:尝试这样的事情:

<script type="text/javascript">

var stopAtValue = 96;

$(function() {
var $elie = $("#super");
rotate(1);
function rotate(degree) {        
    $elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});  
    $elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});                      
    timer = setTimeout(function() {
    if(degree==stopAtValue) {
      // do nothing
    } else {
      rotate(++degree);
    },2);
}
});
</script>

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

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