Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Manage selection fabric js

(function() {

  function add() {
    var red = new fabric.Rect({
      top: Math.random() * canvas.height, left: Math.random() * canvas.width, width: 80, height: 50, fill: 'red' });
    var blue = new fabric.Rect({
      top: Math.random() * canvas.height, left: Math.random() * canvas.width, width: 50, height: 70, fill: 'blue' });
    var green = new fabric.Rect({
      top: Math.random() * canvas.height, left: Math.random() * canvas.width, width: 60, height: 60, fill: 'green' });
    canvas.add(red, blue, green);
  }

  var $ = function(id){return document.getElementById(id)};

  var canvas = this.__canvas = new fabric.Canvas('c');
  var red = new fabric.Rect({
    top: 100, left: 0, width: 80, height: 50, fill: 'red' });
  var blue = new fabric.Rect({
    top: 0, left: 100, width: 50, height: 70, fill: 'blue' });
  var green = new fabric.Rect({
    top: 100, left: 100, width: 60, height: 60, fill: 'green' });
  fabric.Object.prototype.transparentCorners = false;
  canvas.add(red, blue, green)
  var group = $('group'),
      ungroup = $('ungroup'),
      multiselect = $('multiselect'),
      addmore = $('addmore'),
      discard = $('discard');

      addmore.onclick = add;

      multiselect.onclick = function() {
        canvas.discardActiveObject();
        var sel = new fabric.ActiveSelection(canvas.getObjects(), {
          canvas: canvas,
        });
        canvas.setActiveObject(sel);
        canvas.requestRenderAll();
      }

      group.onclick = function() {
        if (!canvas.getActiveObject()) {
          return;
        }
        if (canvas.getActiveObject().type !== 'activeSelection') {
          return;
        }
        canvas.getActiveObject().toGroup();
        canvas.requestRenderAll();
      }

      ungroup.onclick = function() {
        if (!canvas.getActiveObject()) {
          return;
        }
        if (canvas.getActiveObject().type !== 'group') {
          return;
        }
        canvas.getActiveObject().toActiveSelection();
        canvas.requestRenderAll();
      }

      discard.onclick = function() {
        canvas.discardActiveObject();
        canvas.requestRenderAll();
      }


})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript timer countdown with seconds 59 
Javascript :: _.union 
Javascript :: url enocde in javascript 
Javascript :: client position js 
Javascript :: _.isString 
Javascript :: react script for deploy heroku 
Javascript :: javascript if object element exists 
Javascript :: Accessing HTML attributes in DOM 
Javascript :: print blade value in js 
Javascript :: java script layout engine error 
Javascript :: javascript Adding Element to the Outer Array 
Javascript :: javascript Inside a regular function 
Javascript :: javascript typeof operator returns function 
Javascript :: Create JavaScript Generators 
Javascript :: status role discord.js 
Javascript :: React ES6 Variables 
Javascript :: chart js svg word map 
Javascript :: nodejs: express, morgan, mongoose package 
Javascript :: change origin phaser 
Javascript :: phaser random line 
Javascript :: phaser play animation with config.js 
Javascript :: Exercice âge JavaScript 
Javascript :: Expresiones regulares para diferentes tipos de campos de formularios 
Javascript :: function Tom(a, b) { return a + b; } 
Javascript :: js replay animation 
Javascript :: block scoped in js 
Javascript :: loop on each character js 
Javascript :: map method in javascript 
Javascript :: javascript find json value 
Javascript :: javascript sort array of objects by key value ascending and descending order 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =