我们可以写一个让小方块运动的函数:
1 div#demo { 2 width: 100px; 3 height: 100; 4 position: absolute; 5 left: 0; 6 top: 0; 7 } 8 9 10 var div = document.getElementById(‘demo’); 11 var timer = window.setInterval(function () { 12 div.style.left = parseInt(getStyle(div, ‘left’)) + 1 + ‘px’; 13 ifparseInt((getStyle(div, ‘left’)) > 1000) { 14 clearInterval(timer); 15 } 16 }, 10);