How to continue CSS animation after freezing?

I am making a button with animated img. Therefore, when you move the cursor, the car goes to the left and stops in the center. And when you go out - the car goes to the right. I made a fiddle: https://jsfiddle.net/ufwyjd0o/

.button{
  height:150px;
  width: 150px;
  background-color:#468189;
  margin: 100px;
  border-radius: 100%;
  box-shadow: 0px 3px 8px 0px rgba(0,0,0,0.6);
  animation: size 1.5s infinite alternate;
  position: relative;
}

@keyframes size {
    0%   {transform: scale(1.0);
          box-shadow: 0px 3px 8px 0px rgba(0,0,0,0.6); }
    100% {transform: scale(1.05);
          box-shadow: 0px 8px 8px 0px rgba(0,0,0,0.4); }
}

.icon img{
  height:75px;
  width:auto;
  position: absolute;
  top: 40px;
  animation: driveout 1s cubic-bezier(.52,.02,.31,.99) both;
  transform: 1s;
}

@keyframes drive {
    0%   {transform: translate3d(-60px,0,0)}
    5%  {transform: translate3d(60px,0,0)}  
    10% {transform: translate3d(40px,0,0);}
}

@keyframes driveout {
    0%   {transform: translate3d(40px,0,0)} 
    100% {transform: translate3d(200px,0,0)}
}

.button:hover .icon img {
  animation: drive 10s  cubic-bezier(.52,.02,.31,.99) normal;
  animation-play-state: pause;
  display:block;
}
+4
source share
1 answer

If you need different animations on hoveron and hoverout (same as mouseover and mouseout in javascript), then something like this would be a better choice.

.button {
 // what you want to happen on hoverout
 animation: // your hoverout animation
}

.button:hover {
 // what you want to happen on hoverover
 animation: // your hoverover animation.
}
-1
source

Source: https://habr.com/ru/post/1618594/


All Articles