mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 01:57:14 +08:00
fixed glitchy flash on transitions when applying multiple transitions to the same node at different times
This commit is contained in:
parent
bd17b54aa8
commit
e8dcb8e584
58
dist/kinetic-core.js
vendored
58
dist/kinetic-core.js
vendored
@ -67,19 +67,6 @@ Kinetic.GlobalObject = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_addAnimation: function(anim) {
|
|
||||||
anim.id = this.animIdCounter++;
|
|
||||||
this.animations.push(anim);
|
|
||||||
},
|
|
||||||
_removeAnimation: function(id) {
|
|
||||||
var animations = this.animations;
|
|
||||||
for(var n = 0; n < animations.length; n++) {
|
|
||||||
if(animations[n].id === id) {
|
|
||||||
this.animations.splice(n, 1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_pullNodes: function(stage) {
|
_pullNodes: function(stage) {
|
||||||
var tempNodes = this.tempNodes;
|
var tempNodes = this.tempNodes;
|
||||||
for(var n = 0; n < tempNodes.length; n++) {
|
for(var n = 0; n < tempNodes.length; n++) {
|
||||||
@ -92,6 +79,23 @@ Kinetic.GlobalObject = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
|
* animation support
|
||||||
|
*/
|
||||||
|
_addAnimation: function(anim) {
|
||||||
|
anim.id = this.animIdCounter++;
|
||||||
|
this.animations.push(anim);
|
||||||
|
},
|
||||||
|
_removeAnimation: function(anim) {
|
||||||
|
var id = anim.id;
|
||||||
|
var animations = this.animations;
|
||||||
|
for(var n = 0; n < animations.length; n++) {
|
||||||
|
if(animations[n].id === id) {
|
||||||
|
this.animations.splice(n, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
_runFrames: function() {
|
_runFrames: function() {
|
||||||
var nodes = {};
|
var nodes = {};
|
||||||
for(var n = 0; n < this.animations.length; n++) {
|
for(var n = 0; n < this.animations.length; n++) {
|
||||||
@ -140,6 +144,9 @@ Kinetic.GlobalObject = {
|
|||||||
this.frame.lastTime = 0;
|
this.frame.lastTime = 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
|
* utilities
|
||||||
|
*/
|
||||||
_isElement: function(obj) {
|
_isElement: function(obj) {
|
||||||
return !!(obj && obj.nodeType == 1);
|
return !!(obj && obj.nodeType == 1);
|
||||||
},
|
},
|
||||||
@ -147,7 +154,7 @@ Kinetic.GlobalObject = {
|
|||||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
return !!(obj && obj.constructor && obj.call && obj.apply);
|
||||||
},
|
},
|
||||||
_getPoint: function(arg) {
|
_getPoint: function(arg) {
|
||||||
|
|
||||||
if(arg.length === 1) {
|
if(arg.length === 1) {
|
||||||
return arg[0];
|
return arg[0];
|
||||||
}
|
}
|
||||||
@ -829,9 +836,22 @@ Kinetic.Node.prototype = {
|
|||||||
* transition completes
|
* transition completes
|
||||||
*/
|
*/
|
||||||
transitionTo: function(config) {
|
transitionTo: function(config) {
|
||||||
|
var go = Kinetic.GlobalObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* clear transition if one is currently running for this
|
||||||
|
* node
|
||||||
|
*/
|
||||||
|
if(this.transAnim !== undefined) {
|
||||||
|
go._removeAnimation(this.transAnim);
|
||||||
|
this.transAnim = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create new transition
|
||||||
|
*/
|
||||||
var node = this.nodeType === 'Stage' ? this : this.getLayer();
|
var node = this.nodeType === 'Stage' ? this : this.getLayer();
|
||||||
var that = this;
|
var that = this;
|
||||||
var go = Kinetic.GlobalObject;
|
|
||||||
var trans = new Kinetic.Transition(this, config);
|
var trans = new Kinetic.Transition(this, config);
|
||||||
var anim = {
|
var anim = {
|
||||||
func: function() {
|
func: function() {
|
||||||
@ -840,6 +860,9 @@ Kinetic.Node.prototype = {
|
|||||||
node: node
|
node: node
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// store reference to transition animation
|
||||||
|
this.transAnim = anim;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adding the animation with the addAnimation
|
* adding the animation with the addAnimation
|
||||||
* method auto generates an id
|
* method auto generates an id
|
||||||
@ -848,7 +871,8 @@ Kinetic.Node.prototype = {
|
|||||||
|
|
||||||
// subscribe to onFinished for first tween
|
// subscribe to onFinished for first tween
|
||||||
trans.tweens[0].onFinished = function() {
|
trans.tweens[0].onFinished = function() {
|
||||||
go._removeAnimation(anim.id);
|
go._removeAnimation(anim);
|
||||||
|
this.transAnim = undefined;
|
||||||
if(config.callback !== undefined) {
|
if(config.callback !== undefined) {
|
||||||
config.callback();
|
config.callback();
|
||||||
}
|
}
|
||||||
@ -1291,7 +1315,7 @@ Kinetic.Stage.prototype = {
|
|||||||
*/
|
*/
|
||||||
stop: function() {
|
stop: function() {
|
||||||
var go = Kinetic.GlobalObject;
|
var go = Kinetic.GlobalObject;
|
||||||
go._removeAnimation(this.anim.id);
|
go._removeAnimation(this.anim);
|
||||||
go._handleAnimation();
|
go._handleAnimation();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -39,19 +39,6 @@ Kinetic.GlobalObject = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_addAnimation: function(anim) {
|
|
||||||
anim.id = this.animIdCounter++;
|
|
||||||
this.animations.push(anim);
|
|
||||||
},
|
|
||||||
_removeAnimation: function(id) {
|
|
||||||
var animations = this.animations;
|
|
||||||
for(var n = 0; n < animations.length; n++) {
|
|
||||||
if(animations[n].id === id) {
|
|
||||||
this.animations.splice(n, 1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_pullNodes: function(stage) {
|
_pullNodes: function(stage) {
|
||||||
var tempNodes = this.tempNodes;
|
var tempNodes = this.tempNodes;
|
||||||
for(var n = 0; n < tempNodes.length; n++) {
|
for(var n = 0; n < tempNodes.length; n++) {
|
||||||
@ -64,6 +51,23 @@ Kinetic.GlobalObject = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
|
* animation support
|
||||||
|
*/
|
||||||
|
_addAnimation: function(anim) {
|
||||||
|
anim.id = this.animIdCounter++;
|
||||||
|
this.animations.push(anim);
|
||||||
|
},
|
||||||
|
_removeAnimation: function(anim) {
|
||||||
|
var id = anim.id;
|
||||||
|
var animations = this.animations;
|
||||||
|
for(var n = 0; n < animations.length; n++) {
|
||||||
|
if(animations[n].id === id) {
|
||||||
|
this.animations.splice(n, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
_runFrames: function() {
|
_runFrames: function() {
|
||||||
var nodes = {};
|
var nodes = {};
|
||||||
for(var n = 0; n < this.animations.length; n++) {
|
for(var n = 0; n < this.animations.length; n++) {
|
||||||
@ -112,6 +116,9 @@ Kinetic.GlobalObject = {
|
|||||||
this.frame.lastTime = 0;
|
this.frame.lastTime = 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
|
* utilities
|
||||||
|
*/
|
||||||
_isElement: function(obj) {
|
_isElement: function(obj) {
|
||||||
return !!(obj && obj.nodeType == 1);
|
return !!(obj && obj.nodeType == 1);
|
||||||
},
|
},
|
||||||
@ -119,7 +126,7 @@ Kinetic.GlobalObject = {
|
|||||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
return !!(obj && obj.constructor && obj.call && obj.apply);
|
||||||
},
|
},
|
||||||
_getPoint: function(arg) {
|
_getPoint: function(arg) {
|
||||||
|
|
||||||
if(arg.length === 1) {
|
if(arg.length === 1) {
|
||||||
return arg[0];
|
return arg[0];
|
||||||
}
|
}
|
||||||
|
21
src/Node.js
21
src/Node.js
@ -660,9 +660,22 @@ Kinetic.Node.prototype = {
|
|||||||
* transition completes
|
* transition completes
|
||||||
*/
|
*/
|
||||||
transitionTo: function(config) {
|
transitionTo: function(config) {
|
||||||
|
var go = Kinetic.GlobalObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* clear transition if one is currently running for this
|
||||||
|
* node
|
||||||
|
*/
|
||||||
|
if(this.transAnim !== undefined) {
|
||||||
|
go._removeAnimation(this.transAnim);
|
||||||
|
this.transAnim = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create new transition
|
||||||
|
*/
|
||||||
var node = this.nodeType === 'Stage' ? this : this.getLayer();
|
var node = this.nodeType === 'Stage' ? this : this.getLayer();
|
||||||
var that = this;
|
var that = this;
|
||||||
var go = Kinetic.GlobalObject;
|
|
||||||
var trans = new Kinetic.Transition(this, config);
|
var trans = new Kinetic.Transition(this, config);
|
||||||
var anim = {
|
var anim = {
|
||||||
func: function() {
|
func: function() {
|
||||||
@ -671,6 +684,9 @@ Kinetic.Node.prototype = {
|
|||||||
node: node
|
node: node
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// store reference to transition animation
|
||||||
|
this.transAnim = anim;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adding the animation with the addAnimation
|
* adding the animation with the addAnimation
|
||||||
* method auto generates an id
|
* method auto generates an id
|
||||||
@ -679,7 +695,8 @@ Kinetic.Node.prototype = {
|
|||||||
|
|
||||||
// subscribe to onFinished for first tween
|
// subscribe to onFinished for first tween
|
||||||
trans.tweens[0].onFinished = function() {
|
trans.tweens[0].onFinished = function() {
|
||||||
go._removeAnimation(anim.id);
|
go._removeAnimation(anim);
|
||||||
|
this.transAnim = undefined;
|
||||||
if(config.callback !== undefined) {
|
if(config.callback !== undefined) {
|
||||||
config.callback();
|
config.callback();
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ Kinetic.Stage.prototype = {
|
|||||||
*/
|
*/
|
||||||
stop: function() {
|
stop: function() {
|
||||||
var go = Kinetic.GlobalObject;
|
var go = Kinetic.GlobalObject;
|
||||||
go._removeAnimation(this.anim.id);
|
go._removeAnimation(this.anim);
|
||||||
go._handleAnimation();
|
go._handleAnimation();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user