Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Fabricjs configurations

(function() {
  var canvas = this.__canvas = new fabric.Canvas('c');

  var rect = new fabric.Rect({
    left: 150,
    top: 200,
    originX: 'left',
    originY: 'top',
    width: 150,
    height: 120,
    angle: -10,
    fill: 'rgba(255,0,0,0.5)',
    transparentCorners: false
  });

  canvas.add(rect).setActiveObject(rect);

  document.getElementById('rotatingPointOffset').oninput = function() {
    canvas.item(0).controls.mtr.offsetY = -parseFloat(this.value);
    canvas.requestRenderAll();
  };

  function observeBoolean(property) {
    document.getElementById(property).onclick = function() {
      canvas.item(0)[property] = this.checked;
      canvas.renderAll();
    };
  }

  function observeNumeric(property) {
    document.getElementById(property).oninput = function() {
      canvas.item(0)[property] = parseFloat(this.value);
      if (property === 'padding') {
        canvas.item(0).setCoords();
      }
      canvas.requestRenderAll();
    };
  }

  function observeValue(property) {
    document.getElementById(property).oninput = function() {
      canvas.item(0)[property] = this.value;
      canvas.requestRenderAll();
    };
  }

  function observeRadio(property) {
    document.getElementById(property).onchange = function() {
      var name = document.getElementById(this.id).name;
      canvas.item(0)[name] = this.value;
      canvas.renderAll();
    };
  }

  function observeOptionsList(property) {
    var list = document.querySelectorAll('#' + property +
    ' [type="checkbox"]');
    for (var i = 0, len = list.length; i < len; i++) {
      list[i].onchange = function() {
        canvas.item(0)[property](this.name, this.checked);
        canvas.renderAll();
      };
    };
  }

  observeBoolean('hasControls');
  observeBoolean('hasBorders');
  observeBoolean('visible');
  observeBoolean('selectable');
  observeBoolean('evented');
  observeBoolean('transparentCorners');
  observeBoolean('centeredScaling');
  observeBoolean('centeredRotation');

  observeNumeric('padding');
  observeNumeric('cornerSize');
  observeValue('borderColor');
  observeValue('cornerColor');
  observeValue('cornerStrokeColor');
  observeRadio('cornerStyle1');
  observeRadio('cornerStyle2');

  observeOptionsList('setControlVisible');
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript get each element count / occurrences / frequency from a list 
Javascript :: undo pwa 
Javascript :: js append sample 
Javascript :: angualr js checknbox not working js 
Javascript :: on inline style change 
Javascript :: iterating over an array 
Javascript :: focus on child components on single page applications - 2 
Javascript :: get gravatar javascript 
Javascript :: FTP Get a directory listing of the current 
Javascript :: how to check if we reach end of div react hooks 
Javascript :: jq add variable 
Javascript :: Adding Handlers to All Forms 
Javascript :: ios ad mobs 
Javascript :: how we can use pagination in angular material and spring boot 
Javascript :: javascript loop through array of objects es6 
Javascript :: why promise goes to microtask and settimeout to browser api 
Javascript :: react controllers 
Javascript :: count how many times elements in an array are repeated javascript 
Javascript :: trigger many calls JavaScript 
Javascript :: node parse markdown files with frontmatter 
Javascript :: how to get author in wordpress api react 
Javascript :: react native navigation export 
Javascript :: angular interpolation check if value is null 
Javascript :: how to detech my cosle errors in angualr 
Javascript :: js wrap a function pass parameters to function 
Javascript :: typeorm caching queries time limit by id 
Javascript :: last iteration is for loop js ES6 
Javascript :: verify number of times request was made in cypress 
Javascript :: Allowed Blocks in Nested Blocks Component Wordpress 
Javascript :: google.translate.TranslateElement part of page 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =