jquery - CSS 动画 : fire css animation on class active

标签 jquery css css-animations

是否可以在每次上课时启动 css 动画? 预览:我有图像 slider ,每次图像更改时,事件类也会更改为当前图像。

我试图在每次图像改变时触发 css 动画

.article.active {
  height: 75px;
  margin-top: -109px;
  margin-left: -70px;
  color: white;
  width: 100%;
  opacity: 0.8;
  z-index: 105;
}

.article-num {
  background: red;
  float: right;
  margin-top: 20px;
  width: 0;
  height: 32px;
  padding: 0;
  font-size: 27px;
  opacity: 0;
  animation-name: movingnum;
  animation-duration: 4.7s;
  animation-delay: 200ms;
  animation-fill-mode: forwards;
}

.article-paragraph {
  top: 24px;
  background: black;
  width: 0;
  height: 23px;
  padding: 0;
  float: right;
  z-index: 30;
  text-align: right;
  opacity: 0;
  animation-name: movingpar;
  animation-delay: 400ms;
  animation-duration: 4.2s;
  animation-fill-mode: forwards;
}

/* keyframes : */
@keyframes movingnum {
  0%,
  100% {
    width: 0px;
  }
  10%,
  90% {
    width: 31px;
    padding: 6.7px;
    opacity: 1;
  }
}

@keyframes movingpar {
  0%,
  100% {
    width: 0px;
    opacity: 0;
  }
  10%,
  90% {
    width: 300px;
    padding: 11px;
    opacity: 1;
  }
}
<a class="swiper-slide" href="views/fourthArticle.html">
  <video id="ctvideo" class="swiper-slide" loop autoplay src="video/staben2miv101217_700.mp4" value="0" muted></video>
  <div class="article active">
    <span class="article-num">04</span>
    <p class="article-paragraph"><strong>text text text</strong></p>
  </div>
</a>

在上面的例子中,动画只播放了一次。当满足某些特定要求时,我可以以某种方式重播动画吗?就像当父元素或兄弟元素具有 .play 类时。

最佳答案

仅向活跃的 parent 添加动画。

.article.active {
  height: 75px;
  margin-top: -109px;
  margin-left: -70px;
  color: white;
  width: 100%;
  opacity: 0.8;
  z-index: 105;
}

.article-num {
  background: red;
  float: right;
  margin-top: 20px;
  width: 0;
  height: 32px;
  padding: 0;
  font-size: 27px;
  opacity: 0;
 
}
.article.active  .article-num { 
  animation-name: movingnum;
  animation-duration: 4.7s;
  animation-delay: 200ms;
  animation-fill-mode: forwards;}

.article-paragraph {
  top: 24px;
  background: black;
  width: 0;
  height: 23px;
  padding: 0;
  float: right;
  z-index: 30;
  text-align: right;
  opacity: 0;

}
.article.active  .article-paragraph{
  animation-name: movingpar;
  animation-delay: 400ms;
  animation-duration: 4.2s;
  animation-fill-mode: forwards;
}

keyframes : @keyframes movingnum {
  0%,
  100% {
    width: 0px;
  }
  10%,
  90% {
    width: 31px;
    padding: 6.7px;
    opacity: 1;
  }
}

@keyframes movingpar {
  0%,
  100% {
    width: 0px;
    opacity: 0;
  }
  10%,
  90% {
    width: 300px;
    padding: 11px;
    opacity: 1;
  }
}
<a class="swiper-slide" href="views/fourthArticle.html">
  <video id="ctvideo" class="swiper-slide" loop autoplay src="video/staben2miv101217_700.mp4" value="0" muted></video>
  <div class="article active">
    <span class="article-num">04</span>
    <p class="article-paragraph"><strong>text text text</strong></p>
  </div>
</a>

关于jquery - CSS 动画 : fire css animation on class active,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48060336/

相关文章:

javascript - 如何强制同步执行getJSON?

javascript - 协助将jquery捆绑到js变量中以进行条件输出

html - 独立滚动显示 :table-cell divs

html - 如何将 flex box 元素设置为没有宽度的动画?

javascript - 将类添加到已经具有相同类的元素的问题

Jquery 在滚动上淡入 Logo

javascript - 如何使用 JavaScript 找到背景图像的 y 位置(以像素为单位)?

css - 将多个 Bootstrap 类合并为一个 SASS 类

html - 创建简单的按钮以使用 Bootstrap 中的列大小

javascript - 如何设置动画状态完成