Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap + iOS Prevent default scroll action begins from input text field

I've faced up with the following problem:

I have a scroll area which contains list of input text fields.

I use

ontouchmove = function(e){ e. preventDefault(); } 

to prevent global scroll of the page. It works fine except cases when gesture begins from input field.

How can I prevent global scroll of the page when first touch traps to the input field?

Thanks.

like image 930
Alex Avatar asked Nov 04 '22 19:11

Alex


1 Answers

I believe you want to capture the touchmove event using the addEventListener function so that the even doesn't "bubble". Try this:

/* This code prevents users from dragging the page */
var preventDefaultScroll = function(event) {
  event.preventDefault();
  window.scroll(0,0);
  return false;
};
document.addEventListener('touchmove', preventDefaultScroll, false);
like image 104
profMobi Avatar answered Nov 11 '22 06:11

profMobi