2015-02-24 67 views

回答

2

试试这个:

(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/

希望这有助于。

+0

的更多信息:http://fabricjs.com/docs/fabric.StaticCanvas.html – ptCoder 2015-02-24 11:37:49

+0

检查这些演示,不可选择的对象,锁定的对象,等:http://fabricjs.com/customization/ – ptCoder 2015-02-24 11:40:20

+0

谢谢为了您的帮助,但在这里我只想在布料上切换删除鼠标侦听器。详细地说,我只想将删除事件mousedown和mousemove切换到范围选择。 – 2015-02-27 02:57:55

1

我遇到了同样的问题。我解决这个问题的方法是将新选项“可选:false”传递给新的结构对象。

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

感谢您的帮助。我在这里有我的解决方案: 'fabric.util.removeListener(fabric.document,'mousedown',this.onMouseDown);织物.util.removeListener(fabric.document,'mousemove',this.onMouseMove);' – 2015-02-27 03:10:25