js侧边栏运动

js侧边栏运动_第1张图片

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)

}

你可能感兴趣的:(js侧边栏运动)