简单的js实现div抖动

<!DOCTYPE html>
<html class="not-ie no-js" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="css/pbcss.css" rel="stylesheet" type="text/css" />
<title></title>
<style>
.box{position:relative;width:300px;height:100px;}
#hd{width:100px;height:50px;background:red;position:absolute;top:10px;left:5px;z-index:1;}
</style>
</head>
<body>
<div class="box">
<div id="hd"></div>
</div>
</body>
<script>
mfx=function(){
var t=0,z=5,del=function(){clearInterval(mfx.ID);return mfx};
del().ID=setInterval(function(){
var i=t/180*Math.PI,x=Math.sin(i)*z,y=Math.cos(i)*z,s=hd.style;
s.top=x+10+'px',s.left=y+'px';
if((t+=90)>1080)
del();
},30);
}
setInterval(mfx,1200);
</script>
</html>

posted @ 2017-05-26 16:25  路在脚下I  阅读(406)  评论(0)    收藏  举报