【问题标题】:how to change canvas fabric to static canvas如何将画布面料更改为静态画布
【发布时间】:2015-04-10 23:50:21
【问题描述】:

我正在使用 Fabric.js 在 html5 中构建应用程序。 我想删除织物画布的鼠标事件侦听器,使其像静态画布,但我不知道如何。 请帮忙。

【问题讨论】:

    标签: jquery fabricjs


    【解决方案1】:

    试试这个:

    (function() {
      var canvas = this.__canvas = new fabric.StaticCanvas('c');
    
      canvas.add(
        new fabric.Rect({ top: 100, left: 100, width: 50, height: 50, fill: '#f55' }),
        new fabric.Circle({ top: 140, left: 230, radius: 75, fill: 'green' }),
        new fabric.Triangle({ top: 300, left: 210, width: 100, height: 100, fill: 'blue' })
      );
    
      fabric.Image.fromURL('../lib/pug.jpg', function(img) {
        canvas.add(img.set({ left: 400, top: 350, angle: 30 }).scale(0.25));
      });
    
      function animate() {
        canvas.item(0).animate('top', canvas.item(0).getTop() === 500 ? '100' : '500', { 
          duration: 1000,
          onChange: canvas.renderAll.bind(canvas),
          onComplete: animate
        });
      }
      animate();
    })();
    

    来源:http://fabricjs.com/static_canvas/

    希望对您有所帮助。

    【讨论】:

    • 检查这些演示是否有不可选择的对象、锁定的对象等:fabricjs.com/customization
    • 感谢您的帮助,但在此我只想切换删除织物上的鼠标侦听器。详细地说,我只想将删除事件 mousedown 和 mousemove 切换到范围选择。
    • 顺便说一句,我有我的解决方案。 "fabric.util.removeListener(fabric.document, 'mousedown', this.onMouseDown); fabric.util.removeListener(fabric.document, 'mousemove', this.onMouseMove);"
    • 你有一个简单的解决方案:canvas.selection = false;
    【解决方案2】:

    我遇到了同样的问题。我解决它的方法是将选项“selectable:false”传递给新的织物对象。

        this.backgroundFabric = new fabric.Rect({ fill: "black",
                width: dimX,
                height: dimY ,
                top: 0,
                left: 0,
                selectable: false });
    

    【讨论】:

    • 感谢您的帮助。我有我的解决方案:fabric.util.removeListener(fabric.document, 'mousedown', this.onMouseDown); fabric.util.removeListener(fabric.document, 'mousemove', this.onMouseMove);
    猜你喜欢
    • 1970-01-01
    • 2019-11-11
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    相关资源
    最近更新 更多