Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent pull-down-to-refresh of mobile chrome

I want to prevent pull-down-to-refresh of mobile chrome(especially iOS chrome). My web application has vertical panning event with device-width and device-height viewport, but whenever panning down, mobile chrome refreshes itself because of browser's default function. Plus, on Safari browser, screen is rolling during panning event. I want to disable these moves.

Of course, I tried event.preventDefault(); and touch-action: none; But it doesn't look work. Should I add eventListner and touch-action "on body tag"? I expect useful answer with example.

like image 298
Jae Woo Woo Avatar asked Mar 25 '16 01:03

Jae Woo Woo


People also ask

How do I stop swipe from refreshing?

To disable the gesture and progress animation, call setEnabled(false) on the view.

How do I stop Safari from pulling to refresh?

I disabled this behaviour by setting the CSS property touch-action of the target element to none.

What is pull-to-refresh gesture?

Pull-to-refresh is a touchscreen gesture that consists of touching the screen of a computing device with a finger or pressing a button on a pointing device, dragging the screen downward with the finger or pointing device, and then releasing it, as a signal to the application to refresh the contents of the screen.


1 Answers

For latest versions of Chrome:

html, body {     overscroll-behavior-y: contain; } 

Old solution:

Since mobile Chrome >= 56 event listeners are passive by default and passive event listeners can't prevent defaults anymore. See here You have to use active event listeners instead like so:

document.addEventListener('touchstart', touchstartHandler, {passive: false}); document.addEventListener('touchmove', touchmoveHandler, {passive: false}); 
like image 137
Joshua Ott Avatar answered Sep 29 '22 11:09

Joshua Ott