1 2 3 4 5 6 7 37 38 39 40 41 42 43
44 - AA
45 - BB
46 - CC
47 - DD
48 - EE
49
50 51 69 70 71 72 73 74 /* 75 var m = new Move(); 76 //让谁动? 77 m.ele = box; 78 m.start = XX; //开始位置 79 m.target =XXX; 结束值 80 m.direction = "top"; //左右动无需给参数,上下给top 81 m.animation(); 启动动画。 82 * */ 83 function Move() { 84 this.ele = null; 85 this.start = 0; 86 this.target = 100; 87 this.speed = 10; 88 this.direction = "left"; 89 this.offset = "offsetLeft"; 90 this.animation = function() { 91 var o = this; 92 if(o.direction == "top") { 93 o.offset = "offsetTop" 94 } 95 96 var step, 97 i = o.start, 98 timer, 99 current;100 101 function t() {102 current = o.ele[o.offset];103 step = (o.target - current) / o.speed104 step = Math.ceil(step);105 i += step;106 if(Math.abs(i - o.target) < 5) {107 i = o.target;108 clearInterval(timer)109 }110 o.ele.style[o.direction] = i + "px";111 }112 timer = setInterval(t, 20);113 }114 115 }