-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Pinch events *always* block scrolling, can we make it optional? #691
Comments
Having the same issue here |
Same here. Would be nice to have scroll blocking only on touches.length > 1. |
^ That was what I ultimately had to do. Basically, on touchstart, see if there were more than two fingers on the screen, then set that attribute to true. On touchend, I would then set it to false. This gave me the functionality I needed, but it seemed to be kind of hacky. |
Also, I noticed that on iPad that code disables totally the selection, even if I apply delete Hammer.defaults.cssProps.userSelect; before instantiating my element. |
Thanks @lostPixels. Not a bad idea. Would you mind posting a code snippet? |
Certainly. This is a quick copy/paste from my project, hopefully it gives you an idea of how I accomplished it. Note that I used the Hammer.js Jquery plugin, which of course adds another layer of complexity. this.$hammer = $('img').hammer();
this.$hammer.on('touchstart', fingerDown)
.on('touchend', fingerUp)
.on('pinch', setScale);
function fingerDown(e) {
var fingersDown = e.originalEvent.touches.length;
if (this.activeFingers > 1) {
// Lock Scrolling over the zoom element by allowing Hammer.js to fire pinch events.
toggleHammerScrolling(true);
}
}
function fingerUp(e) {
toggleHammerScrolling(false);
}
function toggleHammerScrolling(shouldScroll){
//This is where your implementation may change. Just do .get('pinch').set... on your own hammer object.
this.$hammer.data('hammer').get('pinch').set({
enable: shouldScroll
});
}
function setScale(){
console.log('do pinching stuff here');
} |
Thanks a bunch! |
@lostPixels Did your solution end up working? I tried it, and it's allowing scroll, but the pinch event never fires. |
@robtarr This did work in my use case. I'd verify that you're successfully toggling the pinch enable, which should block scrolling. |
@lostPixels For what is this |
@lostPixels I found another answer from you on Stackoverflow. Here you are using the However, with this fix I'm experiencing issues when allowing the scroll: <meta name="viewport" content="width=device-width, initial-scale=1" /> I am not able to zoom in. |
There's also a patch on master that unblocks where there's only one touch. |
+1, unblocks where there's only one touch make sense, when will the patch release? |
@LabiKyo patch is in 2.0.6 which released a while ago |
Hi, |
I have the same problem as @fedyd , any solutions? In my application, I have some responsive cards with an background image, which can be viewed in fullscreen if pinchout over it. But if I activate pinch on that element, I am not able to scroll the page when I start scrolling on the pinchable item itself. The cards fill a lot of space of the screen, so with this bug my application is totally broken and not usable. Hope anyone has an idea - thanks a lot! |
I'm using 2.0.8 and having pinch enabled still blocks scrolling. I'm not sure why, given the patch that was mentioned upthread. I also couldn't get hammer's const mainElem = document.querySelector("main");
var hammer = new Hammer(mainElem);
mainElem.addEventListener("touchstart", function(event) {
if (event.touches.length >= 2) {
hammer.get("pinch").set({ enable: true });
}
});
mainElem.addEventListener("touchend", function(event) {
if (event.touches.length < 2) {
hammer.get("pinch").set({ enable: false });
}
});
hammer.on("pinch", function(event) {
console.log("pinch");
console.log(event);
}); Hope this helps future viewers of this thread. :) |
I'm also using 2.0.8 and ran into this issue, but I resolved it by using the touchAction property. var hammer = new Hammer(element, { touchAction: 'pan-x pan-y' });
hammer.get('pinch').set({ enable: true });
hammer.on('pinch', function(event) {
console.log(event);
}); |
I've added the below code to my project, and it seems to automatically block scrolling over that element. This is not ideal, the element takes up a lot of real-estate and this breaks the UX.
myElement.get('pinch').set({
enable: true
});
Ideally scrolling would only be blocked if the touches.length > 1.
The text was updated successfully, but these errors were encountered: