<style>
* {
margin: 0px;
padding: 0px;
}
div {
100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div id="d1"></div>
</body>
</html>
<script>
// setInterval("方法名()",间隔时间毫秒)
var d1 = document.getElementById("d1");
function move() {
if(d1.offsetLeft < 500) {
d1.style.marginLeft = d1.offsetLeft + 1 + "px";
}else{
window.clearInterval(x);
}
}
var x = window.setInterval("move()", 10);
</script>