如何将网站背景设置为带模糊的视频?

How to set up website background as a video with blur?

我一直在阅读有关此主题的其他 Stack Overflow 线程,但我似乎无法让它发挥作用。

我正在尝试弄清楚如何将循环播放的模糊视频设置为背景。在这个 Squarespace 网站上看到了我想做的事情:https://geoxor.me/

还没有寻找任何模糊效果的代码,因为我仍在努力使视频部分工作。

我使用的代码:

html

<video id="videoBackground" autoplay muted loop>
  <source src="https://player.vimeo.com/video/144855113">
</video>

css

#videoBackground {
  position: fixed;
  right: 0;
  bottom: 0;
  min-width:  100%;
  min-height: 100%;
}

如果有任何建议,我将不胜感激,感谢您的宝贵时间!

您可以将视频元素包裹在容器中以使视频居中并设置宽度和高度以填满屏幕。然后对于视频,添加 filter: blur() 来模糊背景。请记住,这会使边缘模糊为白色,因此您必须使用 transform: scale 将其放大以隐藏边缘。

#videoBackground {
    width: inherit;
    height: inherit;
    -webkit-filter: blur(15px);
    -o-filter: blur(5px);
    filter: blur(5px);
    object-fit: cover;
    transform: scale(1.06); /* Hide edge blur */
}
#container {
    width: 100vw;
    height: 100vh;
    text-align: center;
    overflow: hidden;
}
<div id="container">
  <video id="videoBackground" autoplay muted loop>
    <source src="https://vod-progressive.akamaized.net/exp=1591758868~acl=%2A%2F1646772055.mp4%2A~hmac=ca002f29c4796df2b022404219ed50625d2baf4043cb622ce78dcb05f8c9edbb/vimeo-prod-skyfire-std-us/01/2944/15/389724705/1646772055.mp4">
  </video>
</div>

video {
  object-fit: cover;
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
    filter: blur(5px);
}

html, body {
  height: 100%;
}
html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 150%;
  line-height: 1.4;
}
body {
  margin: 0;
}

.viewport-header {
  position: relative;
  height: 50vh;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1 {
  font-family: 'Syncopate', sans-serif;
  color: #4a3a27;
  text-transform: uppercase;
  letter-spacing: 3vw;
  line-height: 1.2;
  font-size: 3vw;
  text-align: center;
  span {
    display: block;
    font-size: 10vw;
    letter-spacing: -1.3vw;
  }
}

main {
  width: 80vw;
  left: 10%;
  overflow: auto;
  background: rgba(black, 0.66);
  color: white;
  position: relative;
  padding: 1rem;
padding: 20px;
border: 1px solid #000;
text-align:center;
color: #4a3a27;
font-weight: bold;
}
<video src="https://css-tricks-post-videos.s3.us-east-1.amazonaws.com/blurry-trees.mov" autoplay loop playsinline muted></video>

<header class="viewport-header">
  <h1>
    Explore
    <span>Montana</span>
  </h1>
</header>

<main>
  I love Coding
</main>