javascript - 如何进行旋转然后停止?

标签 javascript jquery rotation

我有一个 div 开始旋转,但我不知道如何让它以一定 Angular 停止。目前所发生的一切都是在继续进行。我的问题是如何让它停在像 96 这样的 Angular 。

<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>

最佳答案

要停止在 96 度,请尝试以下操作:

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

Example fiddle

关于javascript - 如何进行旋转然后停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13608598/

相关文章:

javascript - Express.js,意外的 token <

javascript - strip 错误: unable to perform color detection

javascript - 从 pre/code 标签中删除空格

iOS 7 在标签栏中旋转 View 时, View 右侧不可点击

javascript - 运行 Grunt Express Server 会导致错误 : ENOENT: no such file or directory, open 'static/test.json'

javascript - 获取键为空字符串的对象属性的值

javascript - 在 JavaScript 中搜索和输入

javascript - 绑定(bind) popstate 事件的不同方法

ios - Xamarin 表格 : Camera picture is left rotated when comes to UI in IOS

iphone - 如果移动,UIImageView 将缩放而不是旋转,iOS