亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Fabric JS 如何從另一個函數調用一個函數

Fabric JS 如何從另一個函數調用一個函數

慕容3067478 2022-12-09 16:48:44
我有一個功能,可以在單擊時隱藏和顯示圖像,但我想通過單擊另一個對象來做同樣的事情。這是圖像的代碼    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。
查看完整描述

1 回答

?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

在這里,我為您創建了一個代碼筆,這是一種方法。我試圖創建一個正方形并單擊該正方形我正在切換最后一個復選框的可見性。

部分代碼:

var square = new fabric.Rect({ 

        width: 100, 

        height: 100, 

        fill: '#000',

         left:120

    });

    square.on('mousedown', function(e) {

    if(img.opacity <= 0.5){

    img.opacity = 1;

    }else{

    img.opacity = 0;

    }

    canvas.renderAll();


    });

    canvas.add(img);

    canvas.add(square); 

    canvas.renderAll();


查看完整回答
反對 回復 2022-12-09
  • 1 回答
  • 0 關注
  • 95 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號