js侧边栏运动
2017-10-10 本文已影响0人
乍暖还寒2002
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)
}