0

Working on a web app, and I want to prevent the screen moving around, so I start with this:

 $(document).on("touchmove", false);

... then I realize I have a div that needs to be able to scroll, so I've added:

$(document).on('touchmove', function(e) {
  if (!$(e.target).parents().hasClass( 'touch-moveable' )) {
    e.preventDefault();
  }
});

Works ok, but now scrolling on mobile within that div can cause the whole screen to move around again. Not the end of the world, but... isn't there some way to make everything stay still and only let the one div move around?

EDIT

Ok this works, although I bet it could be consolidated and made way more elegant?:

$(document).on('touchmove', function(e) {
  if (!$(e.target).parents().hasClass( 'touch-moveable' )) {
    e.preventDefault();
  }
});

$('.touch-moveable').on('touchmove',function(e){
  e.stopPropagation();
});
Alesh Houdek
  • 938
  • 2
  • 7
  • 20

0 Answers0