html - 想用这个动画覆盖整页这怎么可能

标签 html css svg css-animations

我正在制作注水动画。我的问题是

  1. 如何让它响应。
  2. 是否需要对 SVG 进行任何更改。
  3. 它目前位于左上角页面的开头,我想显示整页。

我的代码如下。

#banner {
  width: 150px;
  height: 150px;
  background: #fff;
  overflow: hidden;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
  z-index: -1;
  margin-bottom: -50px;
}

#banner .fill {
  animation-name: fillAction;
  animation-iteration-count: 1;
  animation-timing-function: cubic-bezier(.2, .6, .8, .4);
  animation-duration: 6s;
  animation-fill-mode: forwards;
}

#banner #waveShape {
  animation-name: waveAction;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  animation-duration: 0.5s;
  width: 300px;
  height: 150px;
  fill: #04ACFF;
}

@keyframes fillAction {
  0% {
    transform: translate(0, 150px);
  }
  100% {
    transform: translate(0, -5px);
  }
}

@keyframes waveAction {
  0% {
    transform: translate(-150px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}
<div id="banner" align="center">
  <div align="center">
    <svg xml:space="preserve">
      <g class="fill">
        <path fill="#04ACFF" id="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
    c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
    c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
      </g>
    </svg>
  </div>
</div>

我想显示我的动画以覆盖整个页面,这怎么可能。

最佳答案

最简单的方法是给 SVG 一个 viewBox。然后,您可以为 div 指定 100% 的宽度和高度。

#banner {

  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
  z-index: -1;
  margin-bottom: -50px;
}
#banner .fill {
  animation-name: fillAction;
  animation-iteration-count: 1;
  animation-timing-function: cubic-bezier(.2, .6, .8, .4);
  animation-duration: 6s;
  animation-fill-mode: forwards;
}
#banner #waveShape {
  animation-name: waveAction;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  animation-duration: 0.5s;
  width: 300px;
  height: 150px;
  fill: #04ACFF;
}
@keyframes fillAction {
  0% {
    transform: translate(0, 150px);
  }
  100% {
    transform: translate(0, -5px);
  }
}
@keyframes waveAction {
  0% {
    transform: translate(-150px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}
<div id="banner" align="center">
  <div align="center">
    <svg viewBox="0 0 150 150" preserveAspectRatio="none" xml:space="preserve">

        <g class="fill">
          <path fill="#04ACFF" id="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
        </g>


    </svg>
  </div>
</div>

关于html - 想用这个动画覆盖整页这怎么可能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45096558/

相关文章:

java - 当我在电子邮件客户端中设置阻止 HTML 电子邮件时会发生什么

Javascript 图片悬停效果

css - 在 Sass (SCSS) 中转义百分比字符

javascript - 如何在 ReactJS 和 ChartistJS 之间委托(delegate) svg 的渲染责任

css - 使用 CSS 为 "inverted"SVG 路径着色

php - 如何通过apache服务器执行php调用的带有selenium的python脚本?

html - 附加到网站的字体不适用于苹果设备

JavaScript - 清除 HTML5 Canvas 游戏中的多个间隔

里面有文字的CSS形状

javascript - react : Wait until all assets are loaded