“分享到” :效果的封装函数(定时器实现移动)
/*封装上述函数——开始*/
var timer=null; //注意:timer写在外面,我觉得的
var Move=function (v,s) { //速度和总路程这两个变化的设为参数
var owrap=document.getElementById("wrap")
clearInterval(timer);
timer=setInterval(function () {
var iSpeed=v;
if(owrap.offsetLeft==s){
clearInterval(timer)
}else{
owrap.style.left=owrap.offsetLeft+iSpeed+"px";
}
},30)
}
/*封装上述函数——结束*/
window.onload=function () { //用封装函数
var p=document.getElementById("wrap")
p.onmouseover=function () {
Move(10,0)
}
p.onmouseout=function () {
Move(-10,-100)
}
}