我发现好像在move不加 var div1 = document.getElementById('div1'); 也是一样的可以动的
这名话一定要加在move()函数中吗? 加与不加有什么区别吗?
window.onload = function () {
var div1 = document.getElementById('div1');
div1.onmouseover = function () {
move(0);
}
div1.onmouseout = function () {
move(-200);
}
}
var timer = null;
function move(target) {
clearInterval(timer);
timer = setInterval(function () {
var speend = 0;
if(div1.offsetLeft > target){
speend = -10;
} else {
speend = 10;
}
if(div1.offsetLeft == target){
clearInterval(timer);
} else {
div1.style.left = div1.offsetLeft + speend + 'px';
}
}, 30);
}