旋转物体onclick

问题描述:

所以我有代码,当点击“+10”按钮10degree旋转到对象,当点击“+30”按钮30degree旋转到对象,90degree位置是最大可用时应该添加。现在只有一个广告,我不知道如何让它移动到我想移动的程度。旋转物体onclick

http://jsfiddle.net/9Xghf/

var rotateObject = document.getElementById("object"); 
var objectRotation = 0; 

var add10 = document.getElementById("add10"); 
var add30 = document.getElementById("add30"); 

add10.onclick = function(){ 
    rotate(0, 10); 
} 
add30.onclick = function(){ 
    rotate(0, 30); 
} 
function rotate(index, limit){ 
    if(objectRotation < 90 && index <= limit){ 
     index++; 
     objectRotation++; 
     rotateObject.style.transform="rotate(" + objectRotation + "deg)"; 
     rotateObject.style.WebkitTransform="rotate(" + objectRotation + "deg)"; 
     rotateObject.style.msTransform="rotate(" + objectRotation + "deg)"; 
     setTimeout(rotate, 50); 
    }else{ 
    // 90 degree is the max limit for this object 
    } 
} 

该更换计时器:

setTimeout(function(){ 
     rotate(index,limit); 
    }, 50); 

注意:这不会对所有的浏览器

+0

谢谢:)它的工作原理工作,任何想法如何,我可以完全支持浏览器吗? – Driglou 2013-05-02 18:05:25

+0

我会推荐使用'1000/60'作为超时时间而不是'50'来实现每秒60帧的漂亮和流畅。 – howderek 2013-05-02 18:06:44

+0

看看这里,它可能会给你一些指示:http://samuli.hakoniemi.net/cross-browser-rotation-transformation-with-css/ – nicolas 2013-05-02 18:12:20