我创建了一个canvas对象,但是当我尝试使用getZoom()和setZoom时,它表示它们未定义。
canvas = new fabric.Canvas();
new fabric.Image.fromURL(url, function (omg){
canvas.add(omg);
});
canvas.setZoom(canvas.getZoom()*1.1);
我做错了吗?
答案 0 :(得分:5)
您需要将fabric.js版本更新为1.4.13。您可以在此处下载:https://rawgit.com/kangax/fabric.js/master/dist/fabric.js
放大X 2:
var canvas = new fabric.Canvas('canvas');
var url = "http://serio.piiym.net/CVBla/txtboard/thumb/1260285874089s.jpg";
fabric.Image.fromURL(url, function (img){
img.left = 80;
img.top = 50;
canvas.add(img);
});
canvas.renderAll();
alert(canvas.getZoom());
canvas.setZoom(canvas.getZoom()*2);
canvas.renderAll();
alert(canvas.getZoom());
我为你做了一个小提琴:http://jsfiddle.net/tdzoygc4/1/
希望有所帮助。