mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-09 06:14:43 +00:00
109 lines
No EOL
2.8 KiB
JavaScript
109 lines
No EOL
2.8 KiB
JavaScript
fabric.util.object.extend(fabric.StaticCanvas.prototype, {
|
|
|
|
FX_DURATION: 500,
|
|
|
|
/**
|
|
* Centers object horizontally with animation.
|
|
* @method fxCenterObjectH
|
|
* @param {fabric.Object} object Object to center
|
|
* @param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties
|
|
* @return {fabric.Canvas} thisArg
|
|
* @chainable
|
|
*/
|
|
fxCenterObjectH: function (object, callbacks) {
|
|
callbacks = callbacks || { };
|
|
|
|
var empty = function() { },
|
|
onComplete = callbacks.onComplete || empty,
|
|
onChange = callbacks.onChange || empty,
|
|
_this = this;
|
|
|
|
fabric.util.animate({
|
|
startValue: object.get('left'),
|
|
endValue: this.getCenter().left,
|
|
duration: this.FX_DURATION,
|
|
onChange: function(value) {
|
|
object.set('left', value);
|
|
_this.renderAll();
|
|
onChange();
|
|
},
|
|
onComplete: function() {
|
|
object.setCoords();
|
|
onComplete();
|
|
}
|
|
});
|
|
|
|
return this;
|
|
},
|
|
|
|
/**
|
|
* Centers object vertically with animation.
|
|
* @method fxCenterObjectV
|
|
* @param {fabric.Object} object Object to center
|
|
* @param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties
|
|
* @return {fabric.Canvas} thisArg
|
|
* @chainable
|
|
*/
|
|
fxCenterObjectV: function (object, callbacks) {
|
|
callbacks = callbacks || { };
|
|
|
|
var empty = function() { },
|
|
onComplete = callbacks.onComplete || empty,
|
|
onChange = callbacks.onChange || empty,
|
|
_this = this;
|
|
|
|
fabric.util.animate({
|
|
startValue: object.get('top'),
|
|
endValue: this.getCenter().top,
|
|
duration: this.FX_DURATION,
|
|
onChange: function(value) {
|
|
object.set('top', value);
|
|
_this.renderAll();
|
|
onChange();
|
|
},
|
|
onComplete: function() {
|
|
object.setCoords();
|
|
onComplete();
|
|
}
|
|
});
|
|
|
|
return this;
|
|
},
|
|
|
|
/**
|
|
* Same as `fabric.Canvas#remove` but animated
|
|
* @method fxRemove
|
|
* @param {fabric.Object} object Object to remove
|
|
* @param {Function} callback Callback, invoked on effect completion
|
|
* @return {fabric.Canvas} thisArg
|
|
* @chainable
|
|
*/
|
|
fxRemove: function (object, callbacks) {
|
|
callbacks = callbacks || { };
|
|
|
|
var empty = function() { },
|
|
onComplete = callbacks.onComplete || empty,
|
|
onChange = callbacks.onChange || empty,
|
|
_this = this;
|
|
|
|
fabric.util.animate({
|
|
startValue: object.get('opacity'),
|
|
endValue: 0,
|
|
duration: this.FX_DURATION,
|
|
onStart: function() {
|
|
object.setActive(false);
|
|
},
|
|
onChange: function(value) {
|
|
object.set('opacity', value);
|
|
_this.renderAll();
|
|
onChange();
|
|
},
|
|
onComplete: function () {
|
|
_this.remove(object);
|
|
onComplete();
|
|
}
|
|
});
|
|
|
|
return this;
|
|
}
|
|
}); |