<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>circlar movement</title>
<style type="text/css">
#circle{width:30px;height:30px;position: absolute;background-color: lightgreen;left:600px;top:250px;border-radius: 50%;}
</style>
<script type="text/javascript">
window.onload=function(){
var oCircle=document.getElementById(‘circle‘);
var x=500;
var y=200;
var r=100;
var num=0;
setInterval(function(){
num++;
a=Math.sin(num*(Math.PI/180))*r;
b=Math.cos(num*(Math.PI/180))*r;
oCircle.style.left=x+b+‘px‘;
oCircle.style.top=y+a+‘px‘;
},35);
}
</script>
</head>
<body>
<div id="circle"></div>
</body>
</html>
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-05 06:28:13