简体   繁体   中英

Using Hammerjs events within the Kineticjs Canvas

I am trying to use Hammer.js events within the Kinetic.js canvas and can't seem to get it working. I have tried both of the following:

var background = new Kinetic.Rect({
        x: 0,
        y: 0,
        width: image.getWidth(),
        height: image.getHeight(),
        id: "background",
        fill: 'rgba(159, 255, 200, 0.0)',
    });
    pointLayer.add(background);
    pointLayer.draw();

background.hammer().on('tap', function (e) {
        console.log("Background tapped");
});

OR

Hammer(background).on('tap', function (e) {
        console.log("Background tapped");
});

When using the first method, I get an error "has no method 'hammer'". The other I get no messages. Is it possible to use Hammer.js within the Kinetic.js canvas?

It is posibble. But you can not listen kineticjs objects with hammer. You can listen documet elemets. For example canvas of layer or whole stage element.

var transformer = Hammer(stage.getContainer())  //kineticjs stage
transformer.on("transformstart", function(){
   // your code
});

Update:

Currently you can use KineticJS nodes and HammerJS events. (little patch need) First look at demo listed here: https://github.com/lavrton/KineticJS-HammerJS-test

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