1、使方块移动
源码 :
<script type="text/javascript">
var div = document.createElement('div');
document.body.appendChild(div);
div.style.width = "100px";
div.style.height = "100px";
div.style.background = "red";
div.style.position = "absolute";
div.style.left = "0px";
div.style.top = "0px";
//每隔50毫秒执行该函数。
setInterval(function(){
div.style.left = parseInt(div.style.left) + 5 + "px";
div.style.top = parseInt(div.style.top) + 5 + "px";
},50);
</script>
截图: