Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuliandrimba/c64c8a29fedee3a1363354c55e5dbe00 to your computer and use it in GitHub Desktop.
Save giuliandrimba/c64c8a29fedee3a1363354c55e5dbe00 to your computer and use it in GitHub Desktop.
Disable pull to refresh
// Function to disable "pull-to-refresh" effect present in some webviews.
// Especially Crosswalk 12 and above (Chromium 41+) runtimes.
window.addEventListener('load', function() {
var lastTouchY = 0 ;
var maybePreventPullToRefresh = false ;
// Pull-to-refresh will only trigger if the scroll begins when the
// document's Y offset is zero.
var touchstartHandler = function(e) {
if( e.touches.length != 1 ) {
return ;
}
lastTouchY = e.touches[0].clientY ;
// maybePreventPullToRefresh = (preventPullToRefreshCheckbox.checked) && (window.pageYOffset == 0) ;
maybePreventPullToRefresh = (window.pageYOffset === 0) ;
//document.getElementById('txtLog').textContent = "maybePreventPullToRefresh: " + maybePreventPullToRefresh;
};
// To suppress pull-to-refresh it is sufficient to preventDefault the
// first overscrolling touchmove.
var touchmoveHandler = function(e) {
var touchY = e.touches[0].clientY ;
var touchYDelta = touchY - lastTouchY ;
lastTouchY = touchY ;
if (maybePreventPullToRefresh) {
maybePreventPullToRefresh = false ;
//if (touchYDelta > 0) {
e.preventDefault() ;
//document.getElementById('txtLog').textContent = "TouchY: " + touchYDelta;
// console.log("pull-to-refresh event detected") ;
return ;
//}
}
// if (preventScrollCheckbox.checked) {
// e.preventDefault() ;
// return ;
// }
// if (preventOverscrollGlowCheckbox.checked) {
// if (window.pageYOffset == 0 && touchYDelta > 0) {
// e.preventDefault() ;
// return ;
// }
// }
};
document.addEventListener('touchstart', touchstartHandler, false) ;
document.addEventListener('touchmove', touchmoveHandler, false) ;
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment