HTML5 视频背景仅响应位置 :fixed; however I don't want it to scroll with the page

标签 html css responsive-design html5-video

所以,我有这样的东西,一个体面的响应式 html5 背景:

http://codepen.io/anon/pen/yNrdpV

<style>
.video {
  position: fixed;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    transform: translateX(-50%) translateY(-50%);
  -webkit-filter: blur(3px); //change the value according to what suits the best
    -moz-filter: blur(3px); //change the value according to what suits the best
    -o-filter: blur(3px); //change the value according to what suits the best
    -ms-filter: blur(3px); //change the value according to what suits the best
    filter: blur(3px); //change the value according to what suits the best

    overflow: hidden;
}

.margin {
  margin-top: 400px;
}

</style>
<video id="my-video" class="video" muted loop autoplay>
  <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"><!-- 
  <source src="media/demo.ogv" type="video/ogg">
  <source src="media/demo.webm" type="video/webm"> -->
</video>  
<h1 class="margin"> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1><h1> Some Content</h1><h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1><h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>
<h1> Some Content</h1>

所以,我的问题是,如果我将 position:fixed 更改为 position:absolute,它将变得无响应。但是,我不希望视频随页面滚动... 该怎么办? 其他位置如 position:static 是一团糟。

如果您将位置从固定位置更改为固定位置,您会看到垂直滚动条出现在较小的屏幕尺寸上。

编辑: 如果您将其布局/ View 更改为“右”,则该问题仅在 codepen 上可见,因此 HTML/CSS/Java 框位于右侧,预览位于左侧(不是初始的顶部和底部布局)。诡异的。

最佳答案

与其尝试自己完成创建响应式视频元素的所有繁重工作,不如使用 FitVids.js插件来为你做这件事,它正是你需要的。

关于HTML5 视频背景仅响应位置 :fixed; however I don't want it to scroll with the page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32023320/

相关文章:

javascript - Chrome 扩展程序设置

html - CSS居中图像

html - Fontawesome 无法更改文件路径

java - 如何为我的整个应用程序设置默认手机字体

responsive-design - 如何 react 原生文本和图像响应?小型设备中较小的文本和图像,大型设备中较大的文本和图像

css - 使拼贴页面完全响应的最佳方式?

css - Bootstrap 多行元素

javascript - 强制浏览器在 chrome、firefox 上打印背景图片

iOS Chrome 上的 HTML SELECT 不显示 "Done"选项

javascript - 禁用表单按钮