的jsfiddle:http://jsfiddle.net/yJJs7/这个圆圈为什么不围绕正确的中心旋转?
的Javascript:
function main(){
var centerx=250;
var centery=250;
var degrees=0;
var div=document.getElementById('test');
var move=function(){
if(degrees>360)degrees=degrees%360;
var radians = degrees*Math.PI/180;
var newx = Math.cos(radians)*100;
var newy = Math.sin(radians)*100;
div.style.top=(newy+centery)+'px';
div.style.left=(newx+centerx)+'px';
degrees+=10;
};
setInterval(move,50);
console.log(div);
}
main();
HTML:
<div id="test"></div>
<div id="test2"></div>
CSS:
#test{
height:100px;
width:100px;
background:black;
border-radius:100px;
position:fixed;
}
#test2{
position:fixed;
height:30px;
width:30px;
background:black;
border-radius:30px;
position:fixed;
top:250px;
left:250px;
}
第二个div以250x250像素为中心,第一个div应该围绕它旋转。为什么不是?
+1 :-)纯JS 2D动画一个有趣的问题 – Satish 2012-03-03 00:12:45