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

 

css样式:

#box{
width: 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";
}

}

 

posted @ 2016-11-10 11:00  w宇小白  阅读(145)  评论(0编辑  收藏  举报