RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 711825
Accepted
Alexandr_TT
Alexandr_TT
Asked:2020-08-29 16:11:09 +0000 UTC2020-08-29 16:11:09 +0000 UTC 2020-08-29 16:11:09 +0000 UTC

灌水动画

  • 772

我正在尝试制作动画以使圆圈看起来像是装满了水。

我遇到了两个错误,甚至无法通过第三个:

  1. 使用填充是错误的解决方案。
  2. 圆圈在填充后恢复为空(黑色)颜色
  3. 目前我正在使用 tags <img>,但我想将此效果移动到身体{background-image:}上,并且需要一些关于如何做到这一点的指导。

到目前为止我所尝试的:http: //jsfiddle.net/um0rnL56/1/

#banner {
  width: 300px;
  height: 300px;
  position: relative;
}
#banner div {
  position: absolute;
}
#banner div:nth-child(2) {
  -webkit-animation: wipe 6s;
  -webkit-animation-delay: 0s;
  -webkit-animation-direction: up;
  -webkit-mask-size: 300px 3000px;
  -webkit-mask-position: 300px 300px;
  -webkit-mask-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.00, rgba(0, 0, 0, 1)), color-stop(0.25, rgba(0, 0, 0, 1)), color-stop(0.27, rgba(0, 0, 0, 0)), color-stop(0.80, rgba(0, 0, 0, 0)), color-stop(1.00, rgba(0, 0, 0, 0)));
}
@-webkit-keyframes wipe {
  0% {
    -webkit-mask-position: 0 0;
  }
  100% {
    -webkit-mask-position: 300px 300px;
  }
}
<div id="banner">
  <div>
    <img src="http://i.imgur.com/vklf6kK.png" />
  </div>
  <div>
    <img src="http://i.imgur.com/uszeRpk.png" />
  </div>
</div>

来源:注水动画@Arian Faurtosh

css
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2020-08-29T16:11:09Z2020-08-29T16:11:09Z

    这里有四种不同的选择:

    1. 使用缓动

    如果你在一个圆碗里装满液体,它的底部和顶部会比中间填充得更快(因为更宽的中间部分有更多的空间可以覆盖)所以,记住这个粗略的解释,动画应该:快速开始,在中间放慢速度,然后随着碗在顶部再次变窄而迅速结束。

    为此,我们可以使用 CSS3 的缓动特性:cub-bezier (.2, .6, .8, .4).

    请参阅下面的示例。

    (如果你想在easing这里定制,那么这里有一个很好的资源:http ://cubic-bezier.com/#.2,.6,.8,.4 )

    #banner {
      width: 150px;
      height: 150px;
      position: relative;
      background: #000;
      border-radius: 50%;
      overflow: hidden;
    }
    #banner::before {
      content: '';
      position: absolute;
      background: #04ACFF;
      width: 100%;
      bottom: 0;
      animation: wipe 5s cubic-bezier(.2,.6,.8,.4) forwards;
    }
    @keyframes wipe {
      0% {
        height: 0;
      }
      100% {
        height: 100%;
      }
    <div id="banner">
    
    </div>

    2. SVG 美味

    让我们更进一步。假设我们想用 为“水”添加一个波浪表面CSS。我们可以使用 SVG.
    我在 中创建了一个波浪形 SVG 图像Adobe Illustrator,然后使用单独的 CSS 动画对图像进行动画处理,使其在循环中从左向右移动:

    例子

    #banner {
        border-radius: 50%;
        width: 150px;
        height: 150px;
        background: #000;
        overflow: hidden;
        backface-visibility: hidden;
        transform: translate3d(0, 0, 0);
    }
    #banner .fill {
        animation-name: fillAction;
        animation-iteration-count: 1;
        animation-timing-function: cubic-bezier(.2, .6, .8, .4);
        animation-duration: 4s;
        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">
    <div class="fill">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
          <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"/>
        </svg>
    </div>
    </div>

    3.带灌装线

    此示例包括一条填充线(大多数碗从顶部填充,而不是底部填充)。填充线首先从上到下进行动画处理,而该属性会animation-delay阻止填充进行动画处理,直到填充完成。

    #banner {
      border-radius: 50%;
      width: 150px;
      height: 150px;
      background: #000;
      overflow: hidden;
      backface-visibility: hidden;
      transform: translate3d(0, 0, 0);
      position: relative;
    }
    
    #banner .fill {
      transform: translateY(150px);
      animation-name: fillAction;
      animation-iteration-count: 1;
      animation-timing-function: cubic-bezier(.2, .6, .8, .4);
      animation-duration: 4s;
      animation-fill-mode: forwards;
      animation-delay: 0.25s;
    }
    
    #banner .pour {
      width: 6px;
      position: absolute;
      left: 50%;
      margin-left: -3px;
      bottom: 0;
      top: 0;
      background: #009ae6;
      animation-name: pourAction;
      animation-timing-function: linear;
      animation-duration: 0.25s;
    }
    
    #banner #waveShape {
      animation-name: waveAction;
      animation-iteration-count: infinite;
      animation-timing-function: linear;
      animation-duration: 0.5s;
      width: 300px;
      height: 150px;
      fill: #04ACFF;
    }
    
    @keyframes pourAction {
      0% {
        transform: translateY(-100%);
      }
      100% {
        transform: translateY(0);
      }
    }
    
    @keyframes fillAction {
      0% {
        transform: translateY(150px);
      }
      100% {
        transform: translateY(-5px);
      }
    }
    
    @keyframes waveAction {
      0% {
        transform: translate(-150px, 0);
      }
      100% {
        transform: translate(0, 0);
      }
    }
    <div id="banner">
      <div class="pour"></div>
      <div class="fill">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
          <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" />
        </svg>
      </div>
    </div>

    4. 有严重的金光闪闪(具有美丽的美学)

    此示例添加了更多属性CSS以使其更逼真。

    .bowl {
      position: relative;
      border-radius: 50%;
      width: 150px;
      height: 150px;
      box-shadow: inset 0 -5px 0 0 rgba(0, 0, 0, 0.5), inset 0 -20px 5px 0 rgba(0, 0, 0, 0.2), inset -15px 0 5px 0 rgba(0, 0, 0, 0.1), inset 15px 0 5px 0 rgba(0, 0, 0, 0.1);
      background: -moz-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
      background: -webkit-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
      background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 76%, rgba(0, 0, 0, 0.65) 100%);
      margin: 20px;
    }
    .bowl:before {
      overflow: hidden;
      border-radius: 50%;
      content: "";
      box-shadow: inset 0 -5px 0 0 rgba(0, 0, 0, 0.5), inset 0 -20px 5px 0 rgba(0, 0, 0, 0.2), inset -15px 0 5px 0 rgba(0, 0, 0, 0.1), inset 15px 0 5px 0 rgba(0, 0, 0, 0.1);
      background: -moz-radial-gradient(center, ellipse cover, transparent 0%, transparent 60%, rgba(0, 0, 0, 0.65) 81%, black 100%);
      background: -webkit-radial-gradient(center, ellipse cover, transparent 0%, transparent 60%, rgba(0, 0, 0, 0.65) 81%, black 100%);
      background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.65) 81%, #000000 100%);
      position: absolute;
      width: 150px;
      height: 150px;
      z-index: 2;
    }
    .bowl:after {
      content: "";
      width: 60px;
      border-radius: 50%;
      height: 5px;
      background: #039be4;
      box-shadow: inset 0 0 10px 0 #000;
      position: absolute;
      left: 50%;
      margin-left: -30px;
      bottom: 0;
      z-index: 2;
    }
    .bowl .inner {
      border-radius: 50%;
      width: 150px;
      height: 150px;
      background: -moz-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
      background: -webkit-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
      background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 76%, rgba(0, 0, 0, 0.65) 100%);
      overflow: hidden;
      -webkit-backface-visibility: hidden;
      -webkit-transform: translate3d(0, 0, 0);
    }
    .bowl .inner:before {
      content: "";
      width: 20px;
      height: 20px;
      background: rgba(255, 255, 255, 0.2);
      border-radius: 50%;
      position: absolute;
      right: 40%;
      top: 60%;
      z-index: 2;
    }
    .bowl .inner:after {
      content: "";
      width: 20px;
      height: 40px;
      background: rgba(255, 255, 255, 0.2);
      border-radius: 50%;
      position: absolute;
      right: 30%;
      top: 15%;
      transform: rotate(-20deg);
      z-index: 2;
    }
    .bowl .fill {
      -webkit-animation-name: fillAction;
      -webkit-animation-iteration-count: 1;
      -webkit-animation-timing-function: cubic-bezier(0.2, 0.6, 0.8, 0.4);
      -webkit-animation-duration: 4s;
      -webkit-animation-fill-mode: forwards;
    }
    .bowl .waveShape {
      -webkit-animation-name: waveAction;
      -webkit-animation-iteration-count: infinite;
      -webkit-animation-timing-function: linear;
      -webkit-animation-duration: 0.5s;
      width: 300px;
      height: 150px;
      fill: #039be4;
    }
    
    @-webkit-keyframes fillAction {
      0% {
        -webkit-transform: translate(0, 150px);
      }
      100% {
        -webkit-transform: translate(0, 10px);
      }
    }
    @-webkit-keyframes waveAction {
      0% {
        -webkit-transform: translate(-150px, 0);
      }
      100% {
        -webkit-transform: translate(0, 0);
      }
    }
    /* For aesthetics only ------------------------------------------*/
    body {
      margin: 0;
      font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    }
    
    h1 {
      font: 200 1.2em "Segoe UI Light", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
      font-weight: 200;
      color: #fff;
      background: #039be4;
      padding: 20px;
      margin: 0;
      border-bottom: 10px solid #ccc;
    }
    h1 strong {
      font-family: "Segoe UI Black";
      font-weight: normal;
    }
    
    .explanation {
      padding: 20px 40px;
      float: right;
      background: #e64a19;
      -webkit-box-shadow: inset 0 30px 3px 0 rgba(0, 0, 0, 0.5);
      box-shadow: inset 0 3px 5px 0 rgba(0, 0, 0, 0.2);
      border-bottom: 10px solid #ccc;
      max-width: 300px;
    }
    .explanation p {
      color: #fff;
      font-size: 0.8rem;
    }
    <div class="bowl">
      <div class="inner">
        <div class="fill">
          <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
            <path class="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" />
          </svg>
        </div>
      </div>
    </div>

    来源:注水动画@Chris Spittles

    • 18

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5