this.timmer = setInterval(function() {
if (that.complete()) {
that.stop();
that.running = false;
if (callback) {
callback.call(that);
}
return;
}
that.curframe++;
that.enterFrame.call(that);
},
/ this.fps);
return this;
},
// 停止动画
stop: function() {
//console.log('结束动画!');
if (this.timmer) {
clearInterval(this.timmer);
// 清除掉timmer id
this.timmer = undefined;
}
},
go: function(props, duration, tween) {
var that = this;
//console.log(tween)
this.ms.push(function() {
that.init.call(that, props, duration, tween);
that.play.call(that, that.start);
});
return this;
},
//向后一帧
next: function() {
this.stop();
this.curframe++;
this.curframe = this.curframe > this.frames ? this.frames: this.curframe;
this.enterFrame.call(this);
},
//向前一帧
prev: function() {
this.stop();
this.curframe--;
this.curframe = this.curframe < 0 ? 0 : this.curframe;
this.enterFrame.call(this);
},
//跳跃到指定帧并播放
gotoAndPlay: function(frame) {
this.stop();
this.curframe = frame;
this.play.call(this);
},
//跳到指定帧停止播放
gotoAndStop: function(frame) {
this.stop();
this.curframe = frame;
this.enterFrame.call(this);
},
//进入帧动作
enterFrame: function() {
//console.log('进入帧:' + this.curframe)
var ds;
for (var prop in this.initstate) {
//console.log('from: ' + this.initstate[prop]['from'])
ds = this.tween(this.curframe, this.initstate[prop]['from'], this.initstate[prop]['to'] - this.initstate[prop]['from'], this.frames).toFixed(2);
//console.log(prop + ':' + ds)
$util.dom.setStyle(this.obj, prop, ds)
}
},
//动画结束
complete: function() {
return this.curframe >= this.frames;
},
hasNext: function() {
return this.ms.length > 0;
}
}
下面是一个简单的工具,其中有所用到的缓动公式:
util.js
复制代码 代码如下: