CSS3或Javascript - 简单填充动画

Sha*_*lor 0 html javascript css3 keyframe

我正在尝试创建一个简单的动画,当用户将鼠标悬停在元素上时,其中包含的另一个元素将填充其父元素.目前,我有一个JSFiddle就是这样做的.

但是,我想用一些其他功能完成这个,我不确定我在CSS3中实际可以做什么.

  1. 我试图找到一种方法,当内圈完全填充其父级时(即当它的宽度/高度= 300px时),我希望填充暂停并且在动画完成后不会消失.

  2. 当用户将鼠标移动到:悬停范围之外时,我希望动画反转方向而不是突然停止.

我已经用CSS3做到了这一点,但我不确定如果不使用Javascript就可以实现这两个功能.有没有人知道在CSS3中完全这样做的方式/有没有人知道是否有可能在CSS3中执行这最后两个功能,因为我似乎找不到任何东西.

.circle {
        width: 300px;
        height: 300px;
        background-color: white;
        border: 1px solid #000000;
        overflow: hidden;

        border-radius: 150px;
        -moz-border-radius: 150px;
        -webkit-border-radius: 150px;
}

.filler {
        width: 0px;
        height: 0px;
        background-color: red;
        border: none;
        position: relative;
        left: 50%;
        top: 50%;

        border-radius: 150px;
        -mox-border-radius: 150px;
        -webkit-border-radius: 150px;

        animation: empty 1s;
}

.circle:hover .filler {
        animation: fill 2s;
        -moz-animation: fill 2s;
        -webkit-animation: fill 2s;
        background-color: blue;
}

@keyframes fill
      {
        from   {background: red; height: 0px; width: 0px;}
        to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
      }

      @-moz-keyframes fill /* Firefox */
      {
        from   {background: red; height: 0px; width: 0px;}
        to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
      }

      @-webkit-keyframes fill /* Safari and Chrome */
      {
        from   {background: red; height:0px; width:0px;}
        to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
      }

      @keyframes empty
      {
        to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
      }
      @-moz-keyframes empty
      {
        to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
      }
      @-webkit-keyframes empty
      {
        to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
      }
Run Code Online (Sandbox Code Playgroud)

JS小提琴

Vad*_*dim 5

这个简单的动画你不需要关键帧.这是你需要的CSS:

.circle {
  position: relative;
  width: 300px;
  height: 300px;
  background-color: white;
  border: 1px solid #000000;
  border-radius: 150px;
  overflow: hidden;
}

.filter {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background-color: red;
  border-radius: 0px;
  -webkit-transition: all 1s;
  -moz-transition: all 1s;
  -o-transition: all 1s;
  transition: all 1s;
}

.circle:hover .filter {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 150px;
  background-color: blue;
}
Run Code Online (Sandbox Code Playgroud)

和HTML:

<div class="circle">
  <div class="filter"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是一个例子:http://jsbin.com/agekef/1/edit