87,993
社区成员
发帖
与我相关
我的任务
分享
function $(id) {
return document.getElementById(id);
}
function animate(obj,target) {
var timer;
var left = obj.offsetLeft;
var speed = left > target ? -1 : 1;
timer = setInterval(function() {
left = left + speed;
obj.style.left = left + "px";
if(left == target) {
clearInterval(timer);
}
},1)
}
window.onload = function() {
$("one").onmouseover = function() {
//debugger;
animate(this,0);
$("one").onmouseout = function() {
animate(this,-88);
}
};
$("two").onmouseover = function() {
//debugger;
animate(this,0);
$("two").onmouseout = function() {
animate(this,-88);
}
}
}
function animate(obj,target) {
var left = obj.offsetLeft;
var speed = left > target ? -1 : 1;
clearInterval(obj.timer);
obj.timer = setInterval(function() {
left = left + speed;
obj.style.left = left + "px";
if(left == target) {
clearInterval(obj.timer);
}
},1)
}