Created
March 4, 2016 14:39
-
-
Save ismailbaskin/4437fcde2863ca839b33 to your computer and use it in GitHub Desktop.
repress chrome mobile pull to refresh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('load', function() { | |
var maybePreventPullToRefresh = false; | |
var lastTouchY = 0; | |
document.addEventListener('touchstart', function(e) { | |
if (e.touches.length != 1) return; | |
lastTouchY = e.touches[0].clientY; | |
// Pull-to-refresh will only trigger if the scroll begins when the | |
// document's Y offset is zero. | |
maybePreventPullToRefresh = window.pageYOffset == 0; | |
}, false); | |
document.addEventListener('touchmove', function(e) { | |
var touchY = e.touches[0].clientY; | |
var touchYDelta = touchY - lastTouchY; | |
lastTouchY = touchY; | |
if (maybePreventPullToRefresh) { | |
// To suppress pull-to-refresh it is sufficient to preventDefault the | |
// first overscrolling touchmove. | |
maybePreventPullToRefresh = false; | |
if (touchYDelta > 0) { | |
e.preventDefault(); | |
return; | |
} | |
} | |
}, false); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment