Prevent iOS safari from moving web-page window so drag event can happen
Asked Answered
A

4

15

I am using Pep.js for kinetic drag on multi-touch, but my drag events are not being registered because when I try to drag an object in the safari, on iOS, window the window itself moves and follows my drag.

How can I prevent the browser window from following my drag so that the <div> in my webpage can be dragged?

Here is the webpage in question: http://goo.gl/TsHgh. Click on the link and a <div> slides in, it is that div that is draggable. It works on desktop browsers, but can not be dragged on multi-touch because safari moves the window along with my drag.

Andizhan answered 12/6, 2013 at 14:23 Comment(0)
R
38

I have found this solution while working with the #ionicframework

CSS:

html, body {
  overflow:hidden;
}

JS:

$(window).bind(
  'touchmove',
   function(e) {
    e.preventDefault();
  }
);
Rashidarashidi answered 31/5, 2014 at 0:7 Comment(2)
if we apply just overflow rule it will not allow scrolling the page down. I think it should be overflow-xAssignation
Caution -- if you do overflow hidden on either x or y on the body, it will prevent the minimal url bar effect on mobile safari, where you drag up and the URL bar disappears. Also, the touchmove bind doesn't solve the problem.Belovo
A
0

Your animation is what is causing the issue.

Well, the class your animation is being applied to.

Remove the class after the animation is done.

setTimeout(function(){
    $('#tabViewWindow').removeClass('animated').removeClass('bounceInRight');
}, 1200);

Also, to disable scrolling on the window:

html, body{
    overflow:hidden;
}
Andizhan answered 12/6, 2013 at 18:16 Comment(0)
D
0

apply globaly to

html {
  overflow-x: hidden;
}
Degas answered 1/3, 2023 at 14:50 Comment(1)
Have you seen the other answers from 2013-2014?Weinberg
E
-1

Try to add

<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>

To head tag in your html

Erme answered 12/6, 2013 at 14:43 Comment(1)
that just disables zooming. I understand it is good practice to have that, but how will that prevent the window from moving?Andizhan

© 2022 - 2024 — McMap. All rights reserved.