[英]can`t add event listener to object. fabricjs
無法將事件偵聽器添加到對象。 也許有人解決了同樣的問題? 我收到錯誤“未捕獲的TypeError:canvas.on不是函數”。 我也使用jQuery,這可能是問題嗎? 我的代碼:
window.onload = function() {
var canvas = new fabric.Element('canvas');
var imgElement = document.getElementById('uploaded_img');
var width = imgWidth = imgElement.width;
var height = imgHeight = imgElement.height;
if(width >= screen.width){
width = (screen.width - 70);
}
canvas.setWidth(width);
canvas.setHeight(height);
var imgInstance = new fabric.Image(imgElement, {
left: width/2,
top: height/2
});
canvas.add(imgInstance);
canvas.on('mouse:up',function () {
alert('test');
});
}
來自http://fabricjs.com/docs/fabric.Canvas.html
fabric. Canvas
fabric.Element
new Canvas() §
Deprecated:
Use fabric.Canvas instead.
Source:
fabric.js, line 9066
因此不推薦使用Fabric.Element。 因此,強烈建議不要使用它。
無論如何,我在文檔中找不到有關此不推薦使用的“元素”的方法的任何信息。
因此,我想您問題的答案是使用推薦的Canvas構造函數。 我還假定on()方法實際上並不存在於Element上,如錯誤所示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.