為什么我的定時器判斷關(guān)閉不能關(guān)閉?<!doctype html><html><head><meta charset="utf-8"><title>無標題文檔</title><style type="text/css">#div1 {width:200px;height:200px;background:red;position:relative;left:-200px;top:0;}#div1 span{width:20px;height:50px;background:blue;position:absolute;left:200px;top:75px;}</style><script type="text/javascript">window.onload = function(){ var oDiv = document.getElementById('div1'); ? ?oDiv.onmouseover = function(){ startMove(); } } var timer=null; function startMove(){ ? ? clearInterval(timer); var oDiv = document.getElementById('div1');? ? ? ? ? ? timer=setInterval(function(){ if(oDiv.offsetLeft == 0){ clearInterval(timer); }else{ oDiv.style.left = oDiv.offsetLeft+10+'px'; } },30) }</script></head><body><div id="div1"><span id="share">分享</span></div></body></html>
為什么我的定時器判斷關(guān)閉不能關(guān)閉?
未來99
2016-11-17 21:56:07