Fabric.js Clip Canvas (or object group) To Polygon

后端 未结 2 815
难免孤独
难免孤独 2020-12-03 06:03

I have a canvas drawn in Fabric.js that i am adding a group of rectangles to, i want to limit the edges of those rectangles as a group to not go outside a certain area.

2条回答
  •  广开言路
    2020-12-03 06:52

    You may also try this one: http://jsfiddle.net/ZxYCP/198/

    var clipPoly = new fabric.Polygon([
        { x: 180, y: 10 },
        { x: 300, y: 50 },
        { x: 300, y: 180 },
        { x: 180, y: 220 }
    ], {
        originX: 'left',
        originY: 'top',
        left: 180,
        top: 10,
        width: 200,
        height: 200,
        fill: '#DDD', /* use transparent for no fill */
        strokeWidth: 0,
        selectable: false
    });
    

    You can simply use Polygon to clip. Answer is based on @natchiketa idea in this question Multiple clipping areas on Fabric.js canvas

提交回复
热议问题