1 ;(function(global){ 2 var wind = document.getElementById("wind"), count = 0; 3 4 function marque(){ 5 console.log("wind.offsetTop:",wind.offsetTop,"wind.offsetLeft::",wind.offsetLeft); 6 7 8 /*wind.style.left = 12 + wind.offsetLeft + "px"; 9 wind.style.top = 1 + wind.offsetTop + "px"; 10 console.log("wind.offsetTop:",wind.offsetTop,"wind.offsetLeft::",wind.offsetLeft);*/ 11 12 // 上面会不停得计算 offsetLeft offsetTop ,不停得查询,导致浏览器刷新渲染而不利于优化 13 // 就是 缓存布局信息啦 14 count++; 15 wind.style.top = count + "px"; 16 wind.style.left = count + "px"; 17 18 if(wind.offsetTop >= 200){ 19 //stopAnimation(); 20 console.log(111) 21 22 clearInterval(timer); 23 } 24 } 25 26 timer = setInterval(marque,20); 27 console.log(wind.offsetTop) 28 29 })(this)