【问题标题】:"Masking" animation inside a divdiv内的“蒙版”动画
【发布时间】:2021-12-30 19:56:44
【问题描述】:

我制作了一个不错的电影颗粒动画,我将其放在网页上以制作一个不错的 4:3 旧电影类型外观,但是,我不知道如何将动画限制在 div 中。如果它影响它,我正在使用 Bootstrap。基本上,我只希望颗粒位于 div 内部,以便在外部创建一个黑条外观。非常感谢!代码如下:

#titleName {
  font-family: 'Abril Fatface', cursive;
  font-size: 4vw;
  text-align: center;
  white-space: nowrap;
  background-color: rgb(68, 68, 68);
  color: rgb(255, 255, 255);
  margin-top: 0px;
}

#titleName:after {
  animation: grain 2s steps(3) infinite;
  background-image: url("http://creativeloads.com/foto/seamless-film-grain-294.jpg");
  content: "";
  height: 300%;
  left: -50%;
  opacity: 0.1;
  position: fixed;
  top: -100%;
  width: 300%;
}

@keyframes grain {
  0%,
  100% {
    transform: translate(0, 0)
  }
  10% {
    transform: translate(-5%, -10%)
  }
  20% {
    transform: translate(-15%, 5%)
  }
  30% {
    transform: translate(7%, -25%)
  }
  40% {
    transform: translate(-5%, 25%)
  }
  50% {
    transform: translate(-15%, 10%)
  }
  60% {
    transform: translate(15%, 0%)
  }
  70% {
    transform: translate(0%, 15%)
  }
  80% {
    transform: translate(-15%, 5%)
  }
  90% {
    transform: translate(-10%, 10%)
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF=8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/styles.css">
  <link rel="stylesheet" href="scss/custom.scss">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Staatliches&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Abril+Fatface&display=swap" rel="stylesheet">
  <title>Home</title>
</head>

<body style="background-color:rgb(0, 0, 0);">
  <script src="https://unpkg.com/@popperjs/core@2.4.0/dist/umd/popper.min.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <header>
    <!-- Nav Bar -->
  </header>
  <main>
    <!--- Content -->
    <div id="titleName" class="container">
      TITLE
      <div class="noise"></div>
    </div>
  </main>
  <footer>
    <!--- Footer  -->
  </footer>
</body>

</html>

【问题讨论】:

标签: html css animation bootstrap-4


【解决方案1】:

从我收集的关于您的代码的信息来看,您似乎没有为您的容器设置 widthheight,如果您想限制您的子元素,您可以设置其父元素 width 并让您的颗粒为 @ 987654324@

另一种解决方案是创建一个 svg 矩形并将其用作您的 div 的 clip-path

{我将在我的笔记本电脑上添加代码}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-15
    • 2021-02-20
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    相关资源
    最近更新 更多