图片抖动
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
img{
height: 150px;
width: 250px;
}
#dv{
position: absolute;
}
</style>
</head>
<body>
<input type="button" id="btn" value="开始按钮"/>
<input type="button" id="btn_" value="停止按钮"/>
<div id="dv">
<img src="img/2.jpg" />
</div>
<script>
function my$(id){
return document.getElementById(id);
}
my$("btn").onclick=function(){
//定时器
var timeId=setInterval(function(){
//随机数
var x=parseInt(Math.random()*100+1);
var y=parseInt(Math.random()*100+1);
my$("dv").style.top=y+"px";
my$("dv").style.left=x+"px";
},10);
my$("btn_").onclick=function(){
clearInterval(timeId);
}
}
</script>
</body>