javascript平时小例子①(移动的小div)

css样式:

#box{
300px;
height: 300px;
background: deepskyblue;
position: absolute;
margin-right: 20px;
}

 html布局:

<div id="box"></div>

js部分:

window.onload=function(){
abc();
setInterval(abc,50)
function abc(){
var oDiv=document.getElementById("box");
oDiv.style.left=oDiv.offsetLeft+10+"px";
}

}

原文地址:https://www.cnblogs.com/cxy66/p/6050121.html