admin管理员组文章数量:1290796
I'm using fabric.js to define rectangular areas that can be resized. I was wondering if there is any way to set up fabric so that it would resize the element with changing the width / height properties instead of scaleX and scaleY?
I'm using fabric.js to define rectangular areas that can be resized. I was wondering if there is any way to set up fabric so that it would resize the element with changing the width / height properties instead of scaleX and scaleY?
Share Improve this question edited Feb 3, 2016 at 7:48 AndreaBogazzi 14.7k3 gold badges41 silver badges67 bronze badges asked Feb 1, 2016 at 22:09 all jazzall jazz 2,0172 gold badges21 silver badges38 bronze badges2 Answers
Reset to default 10You can use the object:scaling
event.
canvas.on("object:scaling", function(e) {
var target = e.target;
if (!target || target.type !== 'rect') {
return;
}
var sX = target.scaleX;
var sY = target.scaleY;
target.width *= sX;
target.height *= sY;
target.scaleX = 1;
target.scaleY = 1;
});
You should set the dirty flag, that fixed most of the issues for me:
canvas.on("object:scaling", function (e) {
var target = e.target;
if (!target || target.type !== 'rect') {
return;
}
var sX = target.scaleX;
var sY = target.scaleY;
target.width *= sX;
target.height *= sY;
target.scaleX = 1;
target.scaleY = 1;
target.dirty = true;
});
本文标签: javascriptresizing widthheight properties of fabricjs RectsStack Overflow
版权声明:本文标题:javascript - resizing widthheight properties of fabricjs Rects - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741514035a2382776.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论