jquery - FabricJs Ctrl C + Ctrl V -
i'm trying make copy paste action using ctrl+c , ctrl+v fabricjs.
i managed something. object i'm selecting , doing copy paste copied if press again ctrl+v item places inside last one. , if select items changing position.
copy paste actions:
if (map[17] && map[67]) { event.preventdefault(); if(canvas.getactivegroup()){ for(var in canvas.getactivegroup().objects){ var object = fabric.util.object.clone(canvas.getactivegroup().objects[i]); object.set("top", object.top+5); object.set("left", object.left+5); copiedobjects[i] = object; } console.log(copiedobjects); } else if(canvas.getactiveobject()){ var object = fabric.util.object.clone(canvas.getactiveobject()); object.set("top", object.top+5); object.set("left", object.left+5); copiedobject = object; copiedobjects = new array(); console.log(copiedobjects); } }else if(map[17] && map[86]){ event.preventdefault(); console.log(copiedobjects); if(copiedobjects.length > 0){ for(var in copiedobjects){ canvas.add(copiedobjects[i]); } } else if(copiedobject){ canvas.add(copiedobject); } canvas.deactivateall().renderall(); }
i made jsfiddle
please go jsfiddle , select object. press ctrl+c and ctrl+v twice , select 2 object. you'll understand problem then.
thank you
my solution problem have create new object copied object , add canvas
instead of doing
canvas.add(copiedobject);
i doing this
var object = fabric.util.object.clone(copiedobject); object.set("top", object.top+5); object.set("left", object.left+5); copiedobject1 = object; canvas.add(copiedobject1);
and here jsfiddle:- https://jsfiddle.net/n5a1wkfb/2/
Comments
Post a Comment