HTML5 视频缩放模式?
我正在尝试制作全屏 HTML 背景,这很简单。但由于 HTML5 视频在保持宽高比的同时调整了大小以适合容器,因此我无法获得所需的效果。
HTML5 视频是否有不同的缩放模式?我想缩放到填充和裁剪。
这是在 Flash 中完成的所需效果: http://www.caviarcontent.com/
如果您调整窗口大小,您会看到它缩放和裁剪。你永远不会出现黑条。
感谢您的帮助!
I'm trying to make a fullscreen HTML background, which is easy enough. But because HTML5 video get resized to fit the container while maintaining aspect ratio, I can't get the desired effect.
Are there different scale modes for HTML5 video? I'd like to scale to fill-and-crop.
This is the desired effect done in Flash:
http://www.caviarcontent.com/
If you resize the window you'll see it scale and crop. You will never get black bars.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用 CSS 实现此目的的另一种方法是使用 object-fit 属性。这适用于视频或 img 元素
http://caniuse.com/object-fit
http://dev.opera.com/articles/css3-object-fit-object-position /
这仅在 Chrome 31+ 中兼容,但它是最简单的 CSS 解决方案,并且是候选推荐。
Another way to do this with CSS is to use the object-fit property. This works on video or img elements
http://caniuse.com/object-fit
http://dev.opera.com/articles/css3-object-fit-object-position/
This is only compatible in Chrome 31+ but is the simplest CSS solution and is a Candidate Recommendation.
您只需使用 CSS 即可做到这一点:
显然,为转换属性使用适当的供应商前缀额外
:要对图像执行此操作,您可以使用“background-size: cover;”将图像裁剪到所需的空间:
You can do this just with CSS:
Obviously use the appropriate vendor prefixes for the transform property
Bonus: to do this with an image, you can use "background-size: cover;" to crop the image to the desired space:
我通过使用相同的函数我在这里写过来解决这个问题。
如果页面上有一个元素,这个 jQuery 调整大小功能会将视频缩放为浏览器窗口的全屏。
通过更改 browserHeight 和 browserWidth 变量,您可以缩放视频以适合 DIV(确保将该 DIV 设置为溢出:隐藏)。
此函数还将随浏览器窗口动态调整大小。
I figured it out by using the same function I wrote about here.
If you have a element on the page, this jQuery resizing function will scale the video to be full bleed of the browser window.
By changing the browserHeight and browserWidth variables you could have the video scaled to fit a DIV (make sure you set that DIV to overflow:hidden).
This function will also resize dynamically with the browser window.
仅使用 css 快速而肮脏:
如上所示:
http ://web.archive.org/web/20171013204829/www.codesynthesis.co.uk/tutorials/html-5-full-screen-and-responsive-videos
a quick and dirty with css only:
as seen on:
http://web.archive.org/web/20171013204829/www.codesynthesis.co.uk/tutorials/html-5-full-screen-and-responsive-videos
我使用 ExtJS 5 来显示视频,以下代码有效!
```
```
I use ExtJS 5 to show video, the following code works!
```
```