<html><head> <title></title></head><body> <div id="zxc" style="background-color: red;width: 100px;height: 100px;margin-left:100px;"></div> <script type="text/javascript"> var x=document.querySelector('.zxc'); setInterval(function(){x.style.left+=10+'px'; }, 10) </script></body></html>
1 回答
千秋此意
TA贡献158条经验 获得超187个赞
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<div id="zxc" style="background-color:red; width:100px; height:100px; position:absolute; left:100px; top:100px;"></div>
<script type="text/javascript">
var x = document.querySelector('#zxc');
setInterval(function() {
x.style.left = (x.offsetLeft + 10) + 'px';
}, 16)
</script>
</body>
</html>
添加回答
举报
0/150
提交
取消