How to animate element again, after animation-fill-mode: forward?

亡梦爱人 提交于 2021-01-19 06:22:36

问题


So I have a grid of elements and I have set them to fade in one after the other on page load.

So they have a 0.2s delay from one element to the next fading in from opacity 0 to opacity 1.

I then want images in these elements to grow when there grid section is highlighted, but my animation-fill-mode is preventing this.

Any work arounds?

//Expand when hover over.
.main-image {
  transition: transform .2s ease-in-out;
}

#portfolio:hover #portfolio-image {
transform: scale(1.1);
}


// Fade in with delay
@keyframes fadeInFromAbove {
    0% {
        transform: translateY(-30%);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

#portfolio .main-image {
  opacity: 0;
  animation: 0.5s ease-out 0.2s 1 fadeInFromAbove;
  animation-fill-mode: forwards;
}

HTML formatting:

<div id='portfolio' class='main-block'>
      <div id='portfolio-image' class='main-image'></div>
</div>

回答1:


Use two animations like below:

.main-image {
  transition: transform .5s ease-in-out;
  height: 50px;
  margin: 10px;
  background: red;
}

#portfolio:hover #portfolio-image {
  transform: scale(1.1);
}

@keyframes fade {
  100% {
    opacity: 1;
  }
}
@keyframes move {
  0% {
    transform: translateY(-30%);
  }
}

#portfolio .main-image {
  opacity: 0;
  animation: 
    0.5s ease-out 0.2s fade forwards, /* forwards only for opacity */
    0.5s ease-out 0.2s move;
}
<div id='portfolio' class='main-block'>
  <div id='portfolio-image' class='main-image'></div>
</div>


来源:https://stackoverflow.com/questions/65648615/how-to-animate-element-again-after-animation-fill-mode-forward

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!