var src = "http://fabricjs.com/lib/pug.jpg";
// canvas
var canvas = new fabric.Canvas('c');
canvas.backgroundColor = "#F5F5F5";
$("#btnCreateCircle").click(function(evt){
// remove active state of each layer
$("li").removeClass("actived");
canvas.forEachObject(function(obj){
obj.setActive(false);
canvas.renderAll();
});
// object
var circle = new fabric.Circle({
left: fabric.util.getRandomInt(25, canvas.width - 25),
top: fabric.util.getRandomInt(25, canvas.height - 25),
radius: 25,
fill: "#dd0000"
});
circle.hasRotatingPoint = true;
circle.setActive(true);
canvas.add(circle);
canvas.renderAll();
// layer
var id = canvas.getObjects().length - 1;
$("#containerLayers").prepend('<li id="'+ id +'" class="ui-state-default actived"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span> item ' + id + '</li>');
$("#"+id).click(function(evt){
if($(this).hasClass("actived")){
/*
$(this).removeClass("actived");
canvas.item(id).setActive(false);
canvas.renderAll();
*/
// remove active state of all layers and objects
$("li").removeClass("actived");
canvas.forEachObject(function(obj){
obj.setActive(false);
canvas.renderAll();
});
}else{
// remove active state of all layers and objects
$("li").removeClass("actived");
canvas.forEachObject(function(obj){
obj.setActive(false);
//canvas.renderAll();
});
$(this).addClass("actived");
canvas.item(id).setActive(true);
canvas.renderAll();
}
});
});
$("#btnCreateText").click(function(evt){
// remove active state of each layer
$("li").removeClass("actived");
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.