Question

I'm trying create a simple animation that when a user hovers over an element, another element contained within it fills its parent. Currently, I have a JSFiddle that does just that.

BUT, I want to finish this with a few other features that I'm not sure I can actually do in CSS3.

  1. I'm trying to find a way to, upon having the inner circle COMPLETELY fill its parent, (ie when its width/height = 300px), I'd like the fill to pause and not disappear after the animation is complete.

  2. When a user moves their mouse outside the :hover range, I would like the animation to reverse direction as opposed to abruptly stopping.

I've gotten this far with CSS3 but am not sure I can implement these 2 features without resorting to Javascript. Does anyone know of a way of doing this entirely in CSS3/does anyone know if it is possible to do these last two features in CSS3, because I can't seem to find anything.

.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 Fiddle

Was it helpful?

Solution

You don't need keyframes for this simple animation. Here is CSS you need:

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

and HTML:

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

Here is an example: http://jsbin.com/agekef/1/edit

OTHER TIPS

I hope you can try out for this link might help you out

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

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top