We are trying to scroll an element on our iOS web app while preventing the window itself from scrolling. We are capturing the touchmove
event on the window, scrolling the element programmatically and (trying to) prevent the window itself from scroll by calling preventDefault
on the event.
Unfortunately this doesn't work in Mobile Safari. The window continues to scroll underneath our element. The issue sounds exactly like the Webkit bug described in https://bugs.webkit.org/show_bug.cgi?id=163207, but that issue was supposedly fixed in iOS 10.3 whereas I am running 11.3.
Catching touchforcestart
and calling preventDefault
does seem to prevent scrolling of the window, but we are calling it in touchstart
, which seems to be "too late" since the window still scrolls. Scrolling is only prevented next time touchstart
is called.
Any ideas about what is going on? We are baffled since this is clearly a bug but it seems to have been fixed some time ago.
touchmove
listener inside thetouchstart
handler, and for some reason it seems I need to cancel that even as well (withpreventDefault
) to get thetouchmove
to cancel, even with passive turned off. With both{ passive: false }
and thetouchstart
andtouchmove
events both canceled after we handle them, it appears to work great. – Laski