JQuery Mobile - enable scroll

I am currently developing an iOS application using phonegap 1.5 and jQuery Mobile.

I understand that we can turn off page drag and drop using the following javascript:

function preventBehavior(e) { e.preventDefault(); }; document.addEventListener("touchmove", preventBehavior, false); 

However, scrolling content will not work if enabled above.

Is there any way to prevent users from dragging a page, but allow scrolling?

I tried using iScroll. To do this, I will need to manually do

 scrollbar.refresh(); 

under the pageinit event on each page. Unfortunately, I have many pages that require scrolling. = (

Are there any other methods that you can use to enable scrolling without using third-party plugins?

+4
source share
3 answers

Add this to your HTML header

 <script type="text/javascript"> touchMove = function(event) { event.preventDefault(); } </script> 

then install

 ontouchmove="touchMove(event)" 

in the farthest div for every page that you want to disable by dragging and dropping. Example:

 <div id="mypage" ontouchmove="touchMove(event)"> 

Drag and drop will be possible for pages that do not have ontouchmove = "touchMove (event)".

This solution requires that you do not include the ratchet code code of your phone for the preventBehavior () function. Delete or comment:

 //function preventBehavior(e) //{ // e.preventDefault(); //}; //document.addEventListener("touchmove", preventBehavior, false); 

More information here: http://phonegap.pbworks.com/w/page/16494815/Preventing-Scrolling-on-iPhone-Phonegap-Applications

+5
source
 $(document).delegate('.ui-page', 'touchmove', false); 

Most likely, this will work, it will depend on what you want to disable.

+2
source

I am using jQuery Mobile, and the following works for me (executed in DOM ready):

 $('body').on('touchmove', function(e) { e.preventDefault(); }); 

Note that returning false or calling e.stopPropagation () will cause the children of the body to not respond to the touchmove event. You might be doing this in one of your event handlers that stops the event bubble.

+1
source

Source: https://habr.com/ru/post/1401123/