宽高按正弦函数变化的方块

<html>
<head>
<title>test</title>
<style type="text/css">
#box{background-color:#B23AEE;margin:100px auto;}
</style>
</head>
<body>
<div id="box"></div>
<script type="text/javascript">

var box = document.getElementById('box');
var n=0;
function cont()
{
  box.style.width=200+Math.sin(n/180)*100+"px";
  box.style.height=200+Math.cos(n/180)*100+"px";
  n++;
  if(n>=4*Math.PI*180)n=0;
  setTimeout(cont,5);
}
cont();
</script>
</body>
</html>

欢迎分享本文,转载请保留出处:前端ABC » 宽高按正弦函数变化的方块

分享到:更多 ()

发表评论 0