边到边 html5 视频
我正在页面上运行 HTML5 视频,我想根据浏览器的大小调整其边到边的比例。它将被设置为页面上很少的背景。
为了掩饰我的屁股,我使用 VideoJS 来播放视频并处理向后兼容性。库中内置的全屏功能运行良好,但会触发浏览器的本机全屏功能。在某些浏览器中,这意味着黑条,在 Safari 中,这意味着独立于浏览器窗口的字面全屏。这两个我都不想要。
理想情况下,它的功能就像 Supersized 处理图像一样。图像始终设置为页面的整个宽度,并且高度从那里向中心裁剪。当您将页面大小调整得越来越小时,它会达到最小高度并开始向中心裁剪宽度。
我的 JavaScript 知识很少,但我能够戳戳和刺激来弄清楚事情出去。我认为在 VideoJS 库之后放入 Supersized 调整大小脚本并强制它们在 video
标签上工作会以某种方式起作用......至少是一个起始位置,但它不起作用。
有人可以帮助我了解什么功能可以调整页面的宽度、比例的高度以及以一定的宽度或高度向中心裁剪吗?这是我到目前为止所得到的:
这是一个凝灰岩,我知道。太感谢了。
I'm running an HTML5 video on my page and I'd like to make it resize edge to edge in ratio based on the browser's size. It will be set as a background with very little on the page.
To cover my ass, I'm using VideoJS to play the video and handle backwards compatibility. The fullscreen function built into the library works well, but is triggering the browser's native fullscreen function. In some browsers this means black bars, in Safari it means literally fullscreen independent of the browser window. I don't want either of these.
Ideally, it would function like Supersized does for images. The image is always set to the full width of the page, and height is cropped towards the CENTER from there. As you resize the page smaller and smaller, it hits a min-height and begins cropping the width towards the center.
My JavaScript knowledge is minimal, but I'm able to poke and prod to figure things out. I figured that dropping in the Supersized resizing scripts after the VideoJS library and forcing them to work on video
tags would work in some way.. at least a starting place, but it didn't work.
Can someone help me understand what function can adjust width to the page, height in ratio, and crop towards the center at a certain width or height? Here's what I've got so far:
This is a tuffie, I know. Thank you SO much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下操作(基于您发布的演示)
在 video-js-box 中添加类 .fullScreen 并查看会发生什么。
我正在努力实现您上面描述的效果,一旦找到更好的解决方案我会立即通知您。
编辑:好的,我想我找到了一个解决方案 - (版本 2)
复制 - 将上面的代码粘贴到一个新文件中并测试它:)
主要编辑 2:我重构了我的代码,并将其打包为更面向对象的形式。现在它确实会移动(修改了顶部和左侧的 CSS 属性),以便在屏幕比例发生变化时视频保持居中。它仍然会产生奇怪的小跳跃,但效果很好。
我将继续致力于这项任务,因为我认为这是一个很酷的功能。另外,我不知道在闪退期间会发生什么或您希望发生什么。
附:我保留了“单击我”按钮,但禁用它很容易。
You can try the following, (based on the demo you posted)
add the class .fullScreen at the video-js-box and see what happens.
I am trying to achieve the effect you described above, and I 'll let you know as soon as I find a better solution.
EDIT: Ok I think I found a solution - (VERSION 2)
Copy - paste the above code to a new file and test it : )
MAJOR EDIT 2: I refactored my code, and packaged it in a more object oriented form. Now it does move (modified top and left css attributes) so that the video remains centered when the screen ratio changes. It still does a weird little jump but it works quite well.
I will keep working on this task because I think it's a cool feature. Also I have no idea what happens or what would you like to happen during the flash fallback.
ps. I kept the click me button but it is very easy to disable it.
看起来你的问题或多或少已经得到了回答,但对于其他正在寻找一种快速而肮脏的方法来处理这个问题的人来说,我只是拆开了“jQuery Easy Background Resize Plug-In”并使其适用于视频。很容易。
Html 看起来像这样:
Javascript 看起来像这样(查看底部的视频特定内容)
It looks like you're question has been answered, more or less, but for others looking for a quick and dirty way to handle this, I just pulled apart "jQuery Easy Background Resize Plug-In" and made it work for video. Pretty easy.
Html looks like this:
Javascript looks like this (look towards the bottom for the video specific stuff)