When a user swipes a page on a mobile device and it starts scrolling with momentum, is it possible to cancel the scroll and its momentum with Javascript?
When a user swipes a page on a mobile device and it starts scrolling with momentum, is it possible to cancel the scroll and its momentum with Javascript?
Add the style overflow: hidden to the container, and then remove it quickly. This will keep the scrolling position of the document, but stop all momentum.
(To cancel the scroll in this example, press any key, like a)
document.getElementById("myDiv").innerHTML += "A very tall div<br/>".repeat(300)
document.addEventListener("keypress", ()=>{
document.body.style.overflow = "hidden"
setTimeout(()=>
document.body.style.overflow = "", 100)
})
<div id="myDiv"></div>