加水动画 [英] Filling water animation

查看:20
本文介绍了加水动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个擦拭动画,使圆圈看起来它在装满水.我遇到了两个错误,甚至无法解决第三个错误:

  1. 它填错了
  2. 填充后会重置为空(黑色) *
  3. 目前,我正在使用 标签,但我想将此效果移动到 body { background-image: } 并且需要一些指导关于如何做到这一点.

到目前为止我尝试过的:

#banner {宽度:300px;高度:300px;位置:相对;}#banner div {位置:绝对;}#banner div:nth-child(2) {-webkit-animation:擦除6s;-webkit-animation-delay: 0s;-webkit-animation-direction:向上;-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)), 色标(0.27, rgba(0, 0, 0, 0)), 色标(0.80, rgba(0, 0, 0, 0)), 色标(1.00, rgba()0, 0, 0, 0)));}@-webkit-keyframes 擦除 {0% {-webkit-mask-position: 0 0;}100% {-webkit-mask-position: 300px 300px;}}

<div><img src="http://i.imgur.com/uszeRpk.png"/>

<小时>

按照 @anpsmn 的建议为其提供默认遮罩位置,不会再将其重置为黑色.

解决方案

这可以通过一个 div 和一个 ::before 伪元素:

  • #banner 被赋予 border-radius: 50% 来创建一个圆和 overflow: hidden 来裁剪它的孩子里面

  • ::before 伪元素使用 forwards.它从底部开始使用 bottom: 0

  • 背景图像将代替 #banner#banner::before

    上的黑色和蓝色背景应用

兼容性: IE10+ 和所有现代浏览器.-webkit- 前缀属性很可能不再需要您的关键帧动画.在 caniuse.com 上查看浏览器兼容性图表

工作示例

我添加了 cubic-bezier(.2,.6,.8,.4) 这在@ChrisSpittles 的回答 中有解释.它提供了一个整洁的效果!

#banner {宽度:300px;高度:300px;位置:相对;背景:#000;边界半径:50%;溢出:隐藏;}#banner::before {内容: '';位置:绝对;背景:#04ACFF;宽度:100%;底部:0;动画:向前擦拭 5s 三次贝塞尔曲线(.2,.6,.8,.4);}@keyframes 擦除 {0% {高度:0;}100% {高度:100%;}}

I am trying to get a wipe up animation to make a circle look like it's filling with water. I've run into two errors, and haven't been able to even tackle the 3rd one:

  1. It fills up the wrong way
  2. It resets to empty (black) after it has filled *
  3. For now, I am using the <img> tags, but I would like to move this effect to body { background-image: } and need some direction on how to do this.

What I have tried so far:

#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>


Giving it a default mask position as @anpsmn suggested, doesn't reset it to black anymore.

解决方案

This can be achieved with a single div and a ::before pseudo element:

  • The #banner is given border-radius: 50% to create a circle and overflow: hidden to clip its children inside it

  • The ::before pseudo element is animated to 100% height and the animation is paused at 100% using the forwards value. It begins at the bottom with the use of bottom: 0

  • The background images would be applied in place of the black and blue backgrounds on #banner and #banner::before

Compatibility: IE10+ and all modern browsers. The -webkit- prefixed property is most likely no longer necessary for your keyframe animations. Check the browser compatibility chart over here on caniuse.com

Working Example

I have added the cubic-bezier(.2,.6,.8,.4) which is explained in @ChrisSpittles answer. It provides a neat effect!

#banner {
  width: 300px;
  height: 300px;
  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>

这篇关于加水动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆