I am trying to prevent the default scrolling in a web application that contains an HTML5 video element on Mobile Safari. Handling document.ontouchmove and calling e.preventDefault() was the standard way I found to achieve this.
This seems to work everywhere except when you touch the top of a video element where you can start pulling out the page as if it would scroll. This only happens when you force the inclusion of your own video controls. If you do not enable the control attribute and download the video so that it can be played online (for example, on the iPad or in the UIWebView interface with the ability to set InlineMediaPlayback), scrolling is prevented properly. So it looks like this has something to do with the built-in video controls (large play button) that capture the event.
Here is a far-fetched example of what I'm doing:
<!DOCTYPE HTML> <html> <head> <title>HTML5 Video Example</title> <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"> </head> <body style="background: blue;"> <video src="http://cdn.kaltura.org/apis/html5lib/kplayer-examples/media/bbb_trailer_iphone.m4v" controls></video> <script> window.onload = function() { document.ontouchmove = function(e) { e.preventDefault(); } } </script> </body> </html>
Any ideas on workarounds to completely prevent scrolling, even on video? I have already tried processing ontouchmove directly on the video element and it does not work.
Thanks!
javascript html5-video mobile-safari touch
Dan auclair
source share