javascript - rotate object onclick -
so have code supposed add when clicked "+10" button 10degree rotation object, when clicked "+30" button 30degree rotation object, 90degree position max available. ads 1 , dont know how make move degree want move.
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 max limit object } }
replace timer :
settimeout(function(){ rotate(index,limit); }, 50);
nb : won't work browsers
Comments
Post a Comment