0

var canvas = window._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'
    });
    
    canvas.add(red, blue, green);
    
    const alignLeft = document.getElementById('align_left');
    
    alignLeft.onclick = function() {
      const objs = canvas.getActiveObjects();
    }
<script src="https://rawgithub.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" ></canvas>
  <button id="align_left">Align Left</button>

在 FabricJS v3 中寻找一种实用方法来对齐来自 canvas.getActiveObjects 的对象数组的边缘(上、右、下、左)

http://jsfiddle.net/rlightner/bzs0798x/1/

4

1 回答 1

0
$('#align_left').click(function(){canvas.getActiveObject().set({left:0);})
于 2020-03-21T11:42:41.143 回答