var Tween={}; Tween =function(_id) { this.id=_id; }; Tween.prototype = { "id" : null, "x" : null, "y" : null, "m_x" : null, "m_y" : null, "clock" : null, "e_func" : null, "interval" : 300, "playing" : false, "speed" : 0.35, "inteval" : 20, "init" : function (_m_x, _m_y, _e_func) { if (this.playing) { return; } this.x = $(this.id).offsetLeft; this.y = $(this.id).offsetTop; this.m_x = _m_x; this.m_y = _m_y; if (_e_func) { this.e_func = _e_func; } var self=this; this.playing = true; this.clock=setInterval(function(){self.play()}, this.inteval); }, "play" : function () { this.x += (this.m_x - this.x) * this.speed; this.y += (this.m_y - this.y) * this.speed; if(Math.round(this.x) == this.m_x && Math.round(this.y) == this.m_y){ this.x=this.m_x; this.y=this.m_y; clearTimeout(this.clock); if (this.e_func) { this.clock = setTimeout(this.e_func, this.inteval); } this.playing = false; } this.set(this.x,this.y); }, "set" : function (_x, _y) { if (this.m_x) { $(this.id).style.left = _x + 'px'; } if (this.m_y) { $(this.id).style.top = _y + 'px'; } } };