I\'ve created a small HTML5 web application for my company.
This application displays a list of items and everything works fine.
The application is mainly us
Note that overflow-y is not inherited, so you need to set it on ALL block elements.
You can do this with jQuery simply by:
$(document.body).css('overflow-y', 'hidden');
$('*').filter(function(index) {
return $(this).css('display') == 'block';
}).css('overflow-y', 'hidden');
What I did was add following to the touchstart
and touchend
/touchcancel
events:
scrollTo(0, 1)
Since chrome does not scroll if it's not on scrollY position 0
this will prevent chrome from doing pull to refresh.
If it still does not work, try also doing that when the page loads.
The default action of the pull-to-refresh effect can be effectively prevented by doing any of the following :
preventDefault
’ing some portion of the touch sequence, including any of the following (in order of most disruptive to least disruptive):
touch-action: none
” to touch-targeted elements, where appropriate, disabling default actions (including pull-to-refresh) of the touch sequence.overflow-y: hidden
” to the body element, using a div for scrollable content if necessary.chrome://flags/#disable-pull-to-refresh-effect
).See more
Since a couple of weeks I found out that the javascript function that I used to disable the Chrome refresh action won't work anymore. I have made this to solve it:
$(window).scroll(function() {
if ($(document).scrollTop() >= 1) {
$("html").css({
"touch-action": "auto"}
);
} else {
$("html").css({
"touch-action": "pan-down"
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
Pure js solution.
// Prevent pull refresh chrome
var lastTouchY = 0;
var preventPullToRefresh = false;
window.document.body.addEventListener("touchstart", function(e){
if (e.touches.length != 1) { return; }
lastTouchY = e.touches[0].clientY;
preventPullToRefresh = window.pageYOffset == 0;
}, false);
window.document.body.addEventListener("touchmove", function(e){
var touchY = e.touches[0].clientY;
var touchYDelta = touchY - lastTouchY;
lastTouchY = touchY;
if (preventPullToRefresh) {
// To suppress pull-to-refresh it is sufficient to preventDefault the first overscrolling touchmove.
preventPullToRefresh = false;
if (touchYDelta > 0) {
e.preventDefault();
return;
}
}
}, false);
At the moment you can only disable this feature via chrome://flags/#disable-pull-to-refresh-effect - open directly from your device.
You could try to catch touchmove
events, but chances are very slim to achieve an acceptable result.