简体   繁体   中英

Fabric.js drag event does not work

I started to use fabric.js recently and can't set up clicking events. I guided by this page.
HTML:

<section class="canvas-wrap">
    <canvas id="main-canvas" width="1903" height="885"></canvas>
</section>

JAVASCRIPT:

var canvas = new fabric.Canvas('main-canvas');
canvas.on({'touch:drag':function() {
    console.log('dragging');
});

Nothing fancy, but it does not work.

Please, tell me if something is wrong or I should use other way.

At the top of the guide , This demo uses custom version of Fabric with touch events enabled . Therefore, you need to use custom builded fabric.js which includes gesture module.

The detail of how to build is written in https://github.com/kangax/fabric.js

I use mouse down event like this:

myObject.on('mouse:down', function( options ) {
    if (options.target != undefined) {
      //do something when clicking;
    }
});

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