简体   繁体   中英

Fabric js - How do i know currently working canvas

I'm working with fabricjs. I have to know which one is currently working canvas while using multiple canvas(s). Sample code as follows,

<canvas id="canvas1" width="500" height="300">
<canvas id="canvas2" width="500" height="300">
<canvas id="canvas3" width="500" height="300">

var canvas1, canvas2, canvas3 = '';
canvas1 = new fabric.Canvas('canvas1');
canvas2 = new fabric.Canvas('canvas2');
canvas3 = new fabric.Canvas('canvas3');

From here, after adding some objects. I have to identify which one is active canvas.

Probably the simplest thing to do is to add an event handler for mouse over/out events each time you create a canvas, eg

var activeCanvas = null;

canvas1.on('mouse:over', function() {
    activeCanvas = canvas1;
});
canvas1.on('mouse:out', function() {
    activeCanvas = null;
});

// etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM