I enter the world of CSS3 animations and transitions, so please forgive my ignorance. Here is a simplified version of what I'm trying to do:
- I have a ball that pulses endlessly with CSS3 keyframes.
- I want the ball to get bigger and stay that way when I hang over it.
- I want the ball to become small again when I turn my mouse away from it and continue to pulsate (all transitions should be smooth, of course).
Here's my hit on it using a combination of CSS3 animations and transitions (testing this on Chrome so far, hence the webkit prefixes):
@-webkit-keyframes pulsate { from { -webkit-transform: scale(0.7); } to { -webkit-transform: scale(0.8); } } .ball { background: blue; width: 100px; height: 100px; border-radius: 50%; transition: all 1s; -webkit-transform: scale(0.7); -webkit-transform-origin: center center; -webkit-animation-duration: 800ms; -webkit-animation-name: pulsate; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; -webkit-animation-timing-function: ease-in-out; } .ball:hover { -webkit-transform: scale(2); -webkit-animation-play-state: paused; }
jsFiddle Demo
The result is pretty close, but as soon as the ball ends when you hover over it, it becomes small again (I donβt understand why). I also tried disabling animation with -webkit-animation: 0; instead of pausing it, but it doesnβt work either.
I tried a different approach that uses only keyframes (no transitions), trying to call another keyframe set on hover:
@-webkit-keyframes pulsate { from { -webkit-transform: scale(0.7); } to { -webkit-transform: scale(0.8); } } @-webkit-keyframes expand { to { -webkit-transform: scale(2); } } @-webkit-keyframes shrink { to { -webkit-transform: scale(0.7); } } .ball { background: blue; width: 100px; height: 100px; border-radius: 50%; transition: all 2s; -webkit-transform: scale(0.7); -webkit-transform-origin: center center; -webkit-animation-duration: 800ms, 800ms; -webkit-animation-name: shrink, pulsate; -webkit-animation-iteration-count: 1, infinite; -webkit-animation-direction: normal, alternate; -webkit-animation-timing-function: ease-in-out, ease-in-out; } .ball:hover { -webkit-animation-name: expand; -webkit-animation-iteration-count: 1; -webkit-animation-direction: normal; -webkit-animation-fill-mode: forwards; }
jsFiddle Demo
The ball remains large until the mouse is above it, but there is still no smooth transition when the mouse moves away from the ball. I expect it to use cut animation, but it is not.
Am I missing something or is it impossible to implement using only pure CSS at the moment?
// Bound thread, but did not work for me: Stop the animation and start the transition when you hover