如果使用中上,中左等控制点,则可以在该轴上缩放对象。但是,如果使用拐角,则对象始终会均匀缩放。有没有办法禁用拐角控制点上的均匀/比例缩放?
解决方案是在实例上设置uniScaleTransform
为。这绝对不是从Fabric.js文档明显,并在只提到过一次言,第4部分下的对象变换部分true
fabric.Canvas
自1.0版以来,Fabric中还有许多其他与转换相关的属性。其中之一是“ uniScaleTransform”。它是
false
默认设置,可用于启用对象的非均匀缩放;换句话说,它允许在拖动角落时更改对象的比例。
您可以在实例化期间设置标志:
var fabric = new fabric.Canvas(canvasEl, {
// ...
uniScaleTransform: true
});
或稍后更改:
fabric.uniScaleTransform = true;
该标志与物体被忽略lockUniScaling
,因为fabric.js v1.1.9
。
相关源代码:
_onScale: function(e, transform, x, y) {
// rotate object only if shift key is not pressed
// and if it is not a group we are transforming
if ((e.shiftKey || this.uniScaleTransform) && !transform.target.get('lockUniScaling')) {
transform.currentAction = 'scale';
this._scaleObject(x, y);
}
else {
// Switch from a normal resize to proportional
if (!transform.reset && transform.currentAction === 'scale') {
this._resetCurrentTransform(e, transform.target);
}
transform.currentAction = 'scaleEqually';
this._scaleObject(x, y, 'equally');
}
},
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句