简体   繁体   English

响应式Vimeo播放器-全屏错误

[英]Responsive vimeo player - fullscreen bug

To allow for a responsive full-width video, I insert the Vimeo embed-iframe code after the page has loaded. 为了允许响应全角视频,我在页面加载后插入了Vimeo embed-iframe代码。 This allows my script to determine the width of the screen, adjust some variables within the Vimeo code to accommodate the specific size of the screen. 这使我的脚本可以确定屏幕的宽度,并在Vimeo代码中调整一些变量以适应屏幕的特定大小。

Here is the site --> http://leadercastlondon.barkbuilder.com/ . 这是站点-> http://leadercastlondon.barkbuilder.com/ You'll see the video about 2/3rds of the way down the screen. 您将在屏幕下方观看约2/3秒的视频。

Here is the JS code I am using to insert the video onto the page and re-insert if the page is resized. 这是我用来将视频插入页面并在调整页面大小后重新插入的JS代码。

//on page load, insert the video
$(function () {
resizeVideo();
});

//put $(window) in variable
var win = $(window);

// when the page is re-sized
win.resize(function(){

    resizeVideo();
})

function resizeVideo() {
    //code for Vimeo in string
var iFrameString = '<iframe src="//player.vimeo.com/video/74968408?title=0&amp;byline=0&amp;portrait=0&amp;color=ff0179" width="980" height="551" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';

    //calculate width of screen
var siteWidth = $(window).width();

    //width:height ratio
var rate = 1.77858439;
//create string with new width
    var siteWidthString = 'width="' + siteWidth + '"';

var videoHeight = siteWidth / rate;
    //create string with new height
var siteHeightString = 'height="' + videoHeight + '"';

    //regex to replace width within Vimeo iframe string
  var newiFrameString = iFrameString.replace(/width="[0-9]{1,4}"/,siteWidthString);

    //regex to replace height within Vimeo iframe string
    var newiFrameString = newiFrameString.replace(/height="[0-9]{1,4}"/,siteHeightString)

    //insert Vimeo HTML onto page
    $('.row.video').html(newiFrameString);
}

Problem 问题

When the video is played, it's fine. 播放视频时就可以了。 But when the Fullscreen option is selected, this is what i experience on Chrome 31.0.1650.63 Mac: 但是,选择“全屏”选项后,这就是我在Chrome 31.0.1650.63 Mac上遇到的情况:

The video does not go to fullscreen. 视频无法全屏播放。 The sticky nav remains viewable overtop of the page. 粘性导航在页面顶部仍然可见。 Exiting the fullscreen seems to completely break my page. 退出全屏模式似乎完全破坏了我的页面。 I can't scroll up or down. 我无法上下滚动。

On Safari, weird things happening too. 在Safari上,也发生了奇怪的事情。

Anyone run into something like this with a responsive Vimeo player going to fullscreen? 有人在响应式Vimeo播放器进入全屏模式时遇到了这种情况吗? Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

Turns out, it was a conflicting function name that caused all my sorrow. 原来,这是一个冲突的函数名称,这引起了我的所有悲伤。 Doh! h!

I think the main issue here is that you are fully replacing the iframe on every resize. 我认为这里的主要问题是您在每次调整大小时都完全替换iframe。 I believe that when the player goes full screen, a resize event is fired causing that player to not exist anymore, which leads to weird rendering issues. 我认为,当播放器进入全屏模式时,会触发一个尺寸调整事件,导致该播放器不再存在,从而导致奇怪的渲染问题。

It would be a lot more efficient to just update the width and height attributes on the iframe instead of completely replacing it. 仅更新iframe上的widthheight属性而不是完全替换它,将会更有效率。 That will also avoid causing lots of loads to show up in the video's stats. 这样也可以避免导致大量负载出现在视频的统计信息中。

Well, over 1 year later, and this bug punched me the in the face again. 好吧,一年多以后,这个错误再次把我打在了脸上。 But I finally resolved it. 但是我终于解决了。

I had an event on the 'window.resize' which was firing to replace the iframe HTML every time the page changed it's size. 我在“ window.resize”上发生了一个事件,每次页面更改大小时都会触发该事件来替换iframe HTML。 However, the 'fullscreen API' also fires the 'window.resize' event, which was then firing my method to replace the iFrame code....so clicking full screen was wiping out the HTML the video itself and trying to replace it. 但是,“全屏API”也会触发“ window.resize”事件,该事件随后触发了我的方法来替换iFrame代码。...因此,单击全屏显示会清除视频本身的HTML并尝试替换它。

I've found a better way change the iFrame dimensions for a responsive site. 我发现了一种更好的方法来更改响应站点的iFrame尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM