0

ユーザーが要素にカーソルを合わせると、その中に含まれる別の要素がその親を埋める単純なアニメーションを作成しようとしています。現在、私はまさにそれを行う JSFiddle を持っています。

しかし、CSS3 で実際に実行できるかどうかわからない他のいくつかの機能でこれを終了したいと思います。

  1. 内側の円で親を完全に塗りつぶす方法を見つけようとしています(つまり、幅/高さ = 300px の場合)、アニメーションが完了した後、塗りつぶしを一時停止して消えないようにしたいと思います。

  2. ユーザーがマウスを :hover の範囲外に移動すると、アニメーションが突然停止するのではなく、方向を逆にしたいと思います。

私は CSS3 でここまでやってきましたが、Javascript に頼らずにこれら 2 つの機能を実装できるかどうかはわかりません。CSS3でこれを完全に行う方法を知っている人はいますか/ CSS3でこれらの最後の2つの機能を実行できるかどうかを知っている人はいますか.

.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%;}
      }

JSフィドル

4

2 に答える 2

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;
}

および HTML:

<div class="circle">
  <div class="filter"></div>
</div>

以下に例を示します: http://jsbin.com/agekef/1/edit

于 2013-04-05T06:46:49.533 に答える
0

このリンクが役立つかもしれないので試していただければ幸いです

<http://jsfiddle.net/spacebeers/sELKu/3/>
<http://jsfiddle.net/SZqkb/1/>
<http://css-tricks.com/examples/DifferentTransitionsOnOff/>

ありがとう

于 2013-04-05T05:47:04.840 に答える