我有一個功能,可以在單擊時隱藏和顯示圖像,但我想通過單擊另一個對象來做同樣的事情。這是圖像的代碼 function drawCheckbox(left, top, width, height){ var imgClass = new fabric.Image.fromURL('https://image.flaticon.com/icons/svg/33/33281.svg',function(img){ img.width = width; img.height = height; img.left = left; img.top = top; img.set({ hoverCursor: 'default', selectable: true, opacity: 0 }) img.on('mousedown', function(e) { if(e.target.opacity <= 0.5){ e.target.opacity = 1; }else{ e.target.opacity = 0; } canvas.renderAll(); }); canvas.add(img); canvas.renderAll(); }) }這是矩形對象的代碼: function addRect(left, top, width, height, id) { const o = new fabric.Rect({ width: width, height: height, fill: tableFill, stroke: tableStroke, strokeWidth: 2, shadow: tableShadow, originX: 'center', originY: 'center', centeredRotation: true, snapAngle: 45, selectable: true }) const t = new fabric.IText(number.toString(), { fontFamily: 'Calibri', fontSize: 14, fill: '#fff', textAlign: 'center', originX: 'center', originY: 'center' }) const g = new fabric.Group([o, t], { left: left, top: top, centeredRotation: true, snapAngle: 45, selectable: true, type: 'table', id: id, number: number }) canvas.add(g) number++ g.on('selected', function () { // here I want to make de image dissapear, when the object is clicked })我嘗試在矩形內創建圖像,但是當單擊矩形時它什么也沒做。有沒有人有類似的問題?這是代碼筆:codepen.io/Zerro1/pen/PoZvmOE。
Fabric JS 如何從另一個函數調用一個函數
慕容3067478
2022-12-09 16:48:44