admin管理员组文章数量:1181449
I want to fire the 'object:modified' event programmatically. I already tried with "fire" and "trigger" methods.
var canvas = new fabric.Canvas('c');
canvas.on("object:modified", function (e) {
alert("object modified");
});
var text = new fabric.Text('Text', {
fontFamily: 'Hoefler Text',
left: 10,
top: 10
});
canvas.add(text);
$('.fillText').click(function(){
text.setFill($(this).data('color'));
canvas.renderAll();
text.trigger('modified');
});
$('#moveText').click(function(){
text.setLeft(50);
text.setTop(50);
text.setCoords();
canvas.renderAll();
text.trigger('modified');
});
/
I want to fire the 'object:modified' event programmatically. I already tried with "fire" and "trigger" methods.
var canvas = new fabric.Canvas('c');
canvas.on("object:modified", function (e) {
alert("object modified");
});
var text = new fabric.Text('Text', {
fontFamily: 'Hoefler Text',
left: 10,
top: 10
});
canvas.add(text);
$('.fillText').click(function(){
text.setFill($(this).data('color'));
canvas.renderAll();
text.trigger('modified');
});
$('#moveText').click(function(){
text.setLeft(50);
text.setTop(50);
text.setCoords();
canvas.renderAll();
text.trigger('modified');
});
https://jsfiddle.net/gb4u85q4/
Share Improve this question asked Jun 6, 2016 at 10:24 OgreuchaOgreucha 6881 gold badge6 silver badges25 bronze badges2 Answers
Reset to default 17You can trigger events using canvas.trigger('<eventname>', options);
. fire
is deprecated, so you should probably avoid using that.
Since you wanted to trigger object:modified
, you can do that in the following way, while passing which object was modified:
canvas.trigger('object:modified', {target: text});
I updated your JSFiddle with the solution added to it. :)
(note that I changed the alert
to an console.log
because I find alerts annoying, you can view the output of console.log
in the developer tools, which can be opened in for example Google Chrome by pressing F12)
Version 4 breaking changes
Meanwhile you should use fire
.
canvas.fire('object:modified');
In the observabile mixin
observe
,stopObserving
,trigger
are removed. Keep usingon
,off
,fire
. Those are shorter and also all our documentation refer to this kind of names.
For more details see Version 4 breaking changes.
本文标签: javascriptHow to trigger fabricjs quotobjectmodifiedquot event programmaticallyStack Overflow
版权声明:本文标题:javascript - How to trigger fabric.js "object:modified" event programmatically? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738256167a2071607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论