I created a website with jQueryMobile for iOS and Android.
I don\'t want the document itself to scroll. Instead, just an area (a
This is what worked for me for Android and IOS devices.
Imagine that we have a div class="backdrop">
element that we don't want to be scrolled, ever. But we want to be able to scroll over an element that is on top of this backdrop
.
function handleTouchMove(event) {
const [backdrop] = document.getElementsByClassName('backdrop');
const isScrollingBackdrop = backdrop === event.target;
isScrollingBackdrop ? event.preventDefault() : event.stopPropagation();
}
window.addEventListener('touchmove', handleTouchMove, { passive: false });
So, we listen to the touchmove
event, if we're scrolling over the backdrop, we prevent it. If we're scrolling over something else, we allow it but stop its propagation so it doesn't scroll also the backdrop
.
Of course this is pretty basic and can be re-worked and expanded a lot, but this is what fixed my issue in a VueJs2 project.
Hope it helps! ;)