最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Embedding youtube video has scrolling issues on iPhone - Stack Overflow

programmeradmin5浏览0评论

When I'm embedding youtube video in my mobile page, it brings a lot of scrolling issues in iPhone(I guess, it will same problems in other devices too). Users just can't scroll page when their tap on the video itself. Here is code I'm used for embedding

<iframe width="270" height="152" frameborder="0" src=""></iframe>

Can we solve this problem anyway? For example, can we show only thumbnail image of video and play it when user taps on that image. I think the scrolling problem will disappear when there will be image instead of iframe in the page.

I've tried to use html5 version of youtube video, but seems IPhone still renders video in flash way.

 <iframe width="270" height="152" frameborder="0" src=";html5=True"></iframe>

When I'm embedding youtube video in my mobile page, it brings a lot of scrolling issues in iPhone(I guess, it will same problems in other devices too). Users just can't scroll page when their tap on the video itself. Here is code I'm used for embedding

<iframe width="270" height="152" frameborder="0" src="http://www.youtube./embed/nBJCbUMHna4?rel=0"></iframe>

Can we solve this problem anyway? For example, can we show only thumbnail image of video and play it when user taps on that image. I think the scrolling problem will disappear when there will be image instead of iframe in the page.

I've tried to use html5 version of youtube video, but seems IPhone still renders video in flash way.

 <iframe width="270" height="152" frameborder="0" src="http://www.youtube./embed/nBJCbUMHna4?rel=0&html5=True"></iframe>
Share Improve this question asked May 16, 2013 at 12:40 Chuck NorrisChuck Norris 15.2k15 gold badges95 silver badges127 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

The below snippet appears to do the trick without any JavaScript trickery. At the same time this also ensures that you get the nice scrolling momentum on iOS.

*{
    -webkit-overflow-scrolling: touch;
}

I've exactly the same issue on my site, this is not the case in the google blog. I precise that it doesn't scroll the iframe content, it scroll the safari's viewport.

I've try to replace the iframe by an img, no scrolling problem but the video now open in the youtube app...

I'm interested by a solution/workaround

for image solution

var frame = $('#youtubeFrame');
if ( mobileCheck )
{
    frame.replaceWith('<a href="http://www.youtube./watch?v='+youtubes[currentVideo]+'"><img id="imgYoutubeFrame"/></a>');
    $.getJSON("http://gdata.youtube./feeds/api/videos/"+youtubes[currentVideo]+"?v=2&alt=jsonc&callback=?", function(json){
       $("#imgYoutubeFrame").attr("src", json.data.thumbnail.hqDefault);
    });
}

We are having this issue with Vimeo on our mobile site as well. It took us a while to even figure out that users were having the issue. One work around that we are checking out is to add a div layer on top of the video that allows users to scroll as normal and also acts as a custom play button that would distinguish between a scroll and a tap, or perhaps require a double tap to play the video. There is good step by step info on the general principal of how to do that here (https://css-tricks./play-button-youtube-and-vimeo-api/). I'd love to hear if others have found a better option to fix this.

As far as i know you cant have scrolling iFrames on iOS devices
since the scrolling is done with a touch/sliding/gesture
it will scroll the whole page...ie: if you try to scroll
the contents in a iFrame it will scroll the whole page...so the iFrame
will move away with it.

So you could look more in the direction where you dont use scrolling frames,
or make shure theres no need to scroll (content is size of frame it is in),
or use a fancybox-type-of thing where the content is on top instead of in a frame,
or have 2 (jquery) buttons that when pressed do the up/dwn scrolling (instead of a scrollbar),
or have a link which opens the player in a new page,
or the standard way where video opens directly in the iOS player itself (QT/Safari).

发布评论

评论列表(0)

  1. 暂无评论