mirror of
https://github.com/konvajs/konva.git
synced 2026-01-22 21:02:26 +08:00
Add update callback
This commit is contained in:
@@ -38,6 +38,7 @@ class TweenEngine {
|
|||||||
onPause: Function;
|
onPause: Function;
|
||||||
onReset: Function;
|
onReset: Function;
|
||||||
onFinish: Function;
|
onFinish: Function;
|
||||||
|
onUpdate: Function;
|
||||||
|
|
||||||
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
||||||
this.prop = prop;
|
this.prop = prop;
|
||||||
@@ -129,6 +130,7 @@ class TweenEngine {
|
|||||||
}
|
}
|
||||||
update() {
|
update() {
|
||||||
this.setPosition(this.getPosition(this._time));
|
this.setPosition(this.getPosition(this._time));
|
||||||
|
this.fire('onUpdate');
|
||||||
}
|
}
|
||||||
onEnterFrame() {
|
onEnterFrame() {
|
||||||
var t = this.getTimer() - this._startTime;
|
var t = this.getTimer() - this._startTime;
|
||||||
@@ -179,6 +181,7 @@ export class Tween {
|
|||||||
_id: number;
|
_id: number;
|
||||||
onFinish: Function;
|
onFinish: Function;
|
||||||
onReset: Function;
|
onReset: Function;
|
||||||
|
onUpdate: Function;
|
||||||
|
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
var that = this,
|
var that = this,
|
||||||
@@ -249,6 +252,7 @@ export class Tween {
|
|||||||
// callbacks
|
// callbacks
|
||||||
this.onFinish = config.onFinish;
|
this.onFinish = config.onFinish;
|
||||||
this.onReset = config.onReset;
|
this.onReset = config.onReset;
|
||||||
|
this.onUpdate = config.onUpdate;
|
||||||
}
|
}
|
||||||
_addAttr(key, end) {
|
_addAttr(key, end) {
|
||||||
var node = this.node,
|
var node = this.node,
|
||||||
@@ -437,6 +441,11 @@ export class Tween {
|
|||||||
this.onReset();
|
this.onReset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.tween.onUpdate = () => {
|
||||||
|
if (this.onUpdate) {
|
||||||
|
this.onUpdate.call(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* play
|
* play
|
||||||
|
|||||||
@@ -252,6 +252,23 @@ suite('Tween', function () {
|
|||||||
}, 50);
|
}, 50);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tween to call update callback', function (done) {
|
||||||
|
var stage = addStage();
|
||||||
|
var updateCount = 0;
|
||||||
|
|
||||||
|
stage.to({
|
||||||
|
x: 10,
|
||||||
|
duration: 0.01,
|
||||||
|
onUpdate: function () {
|
||||||
|
updateCount++;
|
||||||
|
},
|
||||||
|
onFinish: function () {
|
||||||
|
assert(updateCount === 3, 'updateCount should equal 3');
|
||||||
|
done();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
suite('tween array with different length', function () {
|
suite('tween array with different length', function () {
|
||||||
test('prepare array closed', function () {
|
test('prepare array closed', function () {
|
||||||
var start = [0, 0, 10, 0, 10, 10];
|
var start = [0, 0, 10, 0, 10, 10];
|
||||||
|
|||||||
Reference in New Issue
Block a user