var div1 = document.getElementById('div1');
var span = document.getElementById('span');
var timer;
div1.onmouseover = function(){
hover(10,0);
};
div1.onmouseout = function(){
hover(-10,-150);
}
function hover(speed,target){
clearInterval(timer);
timer = setInterval(function(){
if (div1.offsetLeft == target) {
clearInterval(timer);
} else {
div1.style.left = div1.offsetLeft + speed + 'px';
}
},30)
}
网友评论