I have implemented the hammer.js library for my events. The problem is that multiple events are triggered at the same time.
Can I set somekind of event priority. Let's say when transforming is beeing done all other events are ignored. When transform stops other events can be done.
hammertime.on("transform", function(evt) {
//transform
}
hammertime.on("drag", function(ev) {
//drag
}
I've already tried something like this: Disabiling drag when we start transforming
hammertime.on("transform", function(evt) {
//transform
hammertime.options.drag="false";
}
And enabeling it back when transform is finished
hammertime.on("transformend", function(evt) {
//transformend
hammertime.options.drag="true";
}
This approach works fine except somethimes the drag doesn't get back set to true. I want a 100% working sollution. Please help...
One cheap way to do this is to have your event handlers cooperate:
var transforming = false;
hammertime.on("transformstart", function (ev) { transforming = true; ... });
hammertime.on("transformend", function (ev) { transforming = false; });
hammertime.on("drag", function (ev) { if (!transforming) { ... } });
If Hammer is not always calling your transformend
, then unfortunately all you can do to work around the bug is use some sort of timer that ends your transform if a certain amount of time goes by. It is not perfect, but it can help you recover from the possible bug in Hammer:
var transformTimer = undefined,
transforming = false;
hammertime.on("transform", function (ev) {
transforming = true;
if (transformTimer !== undefined) clearTimeout(transformTimer);
transformTimer = setTimeout(function () {
transformTimer = undefined;
transforming = false;
}, 1000); // end the transform after 1s of idle time.
// your transform code goes here
});
hammertime.on("transformend", function () {
if (transformTimer !== undefined) {
clearTimeout(transformTimer);
transformTimer = undefined;
}
transforming = false;
});
hammertime.on("drag", function (ev) { if (!transforming) { ... } });
try ev.gesture.stopDetect();
see the wiki of Hammer for some details about that! https://github.com/EightMedia/hammer.js/wiki/Event-delegation-and-how-to-stopPropagation---preventDefaults
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With