I have been working on a jQuery Mobile site and have been noticing that once the page was loaded it would jump back to the top of the page after a second or two - giving a horrible user experience if the user had scrolled down immediately.
It turns out this only happens when an HTML 5 VIDEO tag is present on the page - even if it has no associated script, absolute size and even if it's in an iframe.
I made a sample test page to demonstrate:
HOW TO TEST BEHAVIOR
- Open the jsfiddle http://jsfiddle.net/MR966/1
- Click
Run
- Click within the output panel IMMEDIATELY and hit space bar a couple times to scroll down. You must do this the instant the page loads.
- After the Youtube Video has loaded the page will jump to the top.
- Click
Run
and try again if you weren't fast enough.
<HEAD>
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.css" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.js"
<BODY>
<h1>JQuery Mobile Video Jump</h1>
<div class="fake-content"></div>
<div class="fake-content"></div>
<div class="fake-content"></div>
<div class="fake-content"></div>
<div class="fake-content"></div>
<div class="fake-content"></div>
<div class="fake-content"></div>
<iframe width="640" height="390" src="//www.youtube.com/embed/EQ1HKCYJM5U" frameborder="0" allowfullscreen></iframe>
The content can be anything - just long enough to be at least one screen length in height.
.fake-content
{
margin: 1em;
background: orange;
height: 10em;
}
NOTES
- Removing jQuery Mobile stops this behavior : http://jsfiddle.net/MR966/2/ (you'll see the background is yellow showing it wasn't initialized). So it is definitely doing something to cause this.
- Removing the video stops this behavior.
- This happens for pure video tags, and YouTube - which is somewhat surprising considering they're within an externally loaded iFrame.
- The word 'video' doesn't appear once in the jQuery Mobile sourcecode!
- This happens on Chrome / iPad / IE / Firefox.
- On an iPad it's particularly bad because the page doesn't jump to the top until the scrolling has completely stopped due to de-acceleration.
- If you don't see the issue keep trying, use a slower internet connection or copy out the HTML from the JSFiddle to a local page.
- On my actual page with other resources this is a much bigger issue than on this simple quick-fire test page.
I have video on each of my pages and if I can't fix this I'll need to abandon JQM at the eleventh hour :-/