请问这样的代码:为什么鼠标移出div后,方块没有缩回去
鼠标移出后,红色部分会突然消失,然后又出现,并没有缩回屏幕外
var div1 = document.getElementById('div1'),
share = document.getElementById('share'),
timer = null;
window.onload = function(){
var div1 = document.getElementById('div1');
div1.onmouseover = function(){
startMove();
};
div1.onmouseout = function(){
div1.style.left = -200 + 'px'; //这里
};
}
function startMove(){
var div1 = document.getElementById('div1');
clearInterval(timer);
timer = setInterval(function(){
if(div1.offsetLeft != 0){
div1.style.left = div1.offsetLeft + 10 + 'px';
}
}, 30);
}