Js控制滑鼠滑動圖片
阿新 • • 發佈:2019-01-07
window.onload = function(){
function $(id) {
return document.getElementById(id);
}
var num = 0;
var timer = null;
// //控制圖片向上移動
$("up").onmouseover = function (){
timer = setInterval(fun,30);
function fun(){
num-=2 ;
if(num<-1070){
clearInterval(timer);
}else{
$("mi").style.top=num+"px";
}
}
}
//控制圖片向下移動
$("down").onmouseover = function (){
timer = setInterval(fun,30);
function fun(){
num+=2;
if(num>0){
clearInterval(timer);
}else{
$("mi").style.top=num+"px";
}
}
}
//滑鼠移走後圖片停止移動
$("all").onmouseout = function(){
clearInterval(timer);
}
}