所以我有一个应该在点击“+10”按钮时添加的代码10degree旋转到对象,当点击“+30”按钮30度旋转到对象时,90度的位置最大可用。现在它只有一个广告,我不知道如何让它移动到我希望它移动的程度。
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
}
}
答案 0 :(得分:2)
用这个替换计时器:
setTimeout(function(){
rotate(index,limit);
}, 50);
nb:这不适用于所有浏览器