Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't unbind hammer from element (jquery) still not working #538

Closed
fw25 opened this issue Apr 16, 2014 · 7 comments
Closed

Can't unbind hammer from element (jquery) still not working #538

fw25 opened this issue Apr 16, 2014 · 7 comments

Comments

@fw25
Copy link

fw25 commented Apr 16, 2014

This is still problem as http://jsfiddle.net/LSrgh/65/ shows. Any suggestions?

@lloiser
Copy link
Contributor

lloiser commented Apr 17, 2014

calling Hammer(el,{prevent_default: true}) returns an instance of hammer. this instance is then used to unbind from events!
you also have to pass the same function into off as into on (because it simply calls addEventListener under the hood which needs the correct
see http://jsfiddle.net/LSrgh/66/

if you use the jquery hammer plugin you can simply call off without the function because bind/unbinding to an event is handled by jquery
see http://jsfiddle.net/LSrgh/67/

@fw25
Copy link
Author

fw25 commented Apr 21, 2014

Dear Lukas,

Normally i would unbind events from an instance. Some how I am not able to do this with Hammer. See example http://jsfiddle.net/LSrgh/76/. What am I doing wrong?

With kind regards,

Felix Wagemakers

On 17 apr. 2014 (16), at 21:32, Lukas [email protected] wrote:

calling Hammer(el,{prevent_default: true}) returns an instance of hammer. this instance is then used to unbind from events!
you also have to pass the same function into off as into on (because it simply calls addEventListener under the hood which needs the correct
see http://jsfiddle.net/LSrgh/66/

if you use the jquery hammer plugin you can simply call off without the function because bind/unbinding to an event is handled by jquery
see http://jsfiddle.net/LSrgh/67/


Reply to this email directly or view it on GitHub.

@robbue
Copy link

robbue commented Apr 22, 2014

I asked about this issue on the jQuery plugin repo to: hammerjs/jquery.hammer.js#14

From jQuery docs:

Calling .off() with no arguments removes all handlers attached to the elements.

This dosen't seem to happen with hammer

@jdinard
Copy link

jdinard commented Oct 10, 2014

This doesn't work. This is a big issue considering that this is designed for mobile devices.

Essentially Hammer.js leaks memory. Even after you remove the item, the event will not be unbound and will cause a memory leak.

@boynet
Copy link

boynet commented Apr 26, 2015

@jdinard is this still true?

@Bushjumper
Copy link

I've updated you jsBin example from above to work.

var el = document.getElementById("el");
var onkeys="touch tap release";
var ham = Hammer(el,{prevent_default: true});

var fun = function(ev) {
    console.log(ev.type);
};

ham.on(onkeys, fun);
ham.off(onkeys, fun);

@runspired
Copy link
Contributor

Working jsbin for how to not leak memory: http://jsfiddle.net/LSrgh/141/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants