javascript - 根据父元素属性更改元素的 CSS 属性

标签 javascript jquery css animation

我正在使用 js-caurousal 来更改工作正常的背景图像。除此之外,我还为每张幻灯片添加了标题,我使用 animation.csswow.js 制作了淡入淡出效果的动画。

我遇到的问题是动画只播放一次,我想在幻灯片事件时为字幕文本播放动画。我试图寻找解决方案,但找不到太多。

所以我想从具有 slide-caption 类的元素中添加和删除 wow fadeIn

下面是幻灯片的代码

<div class="js-carousel u-carousel-v5" data-autoplay="true" data-infinite="true" data-fade="true" data-speed="4000">
  <div class="js-slide g-bg-img-hero g-height-100vh--md g-min-height-300" aria-hidden="true" style="background-image: url(assets/img/1.jpg);">
    <h3 class="slide-caption wow fadeIn" data-animation="animated fadeIn" data-wow-delay="4s">Image One</h3>
  </div>

  <div class="js-slide g-bg-img-hero g-height-100vh--md g-min-height-300" aria-hidden="true" style="background-image: url(assets/img/2.jpg);">
    <h3 class="slide-caption wow fadeIn" data-animation="animated fadeIn" data-wow-delay="4s">Image Two</h3>
  </div>
</div>

我如何使用以下 $( ":hidden").attr( "aria-hidden", "true")slide-caption 中添加和删除 css >

最佳答案

我认为您应该将它用作属性选择器 并执行如下操作:

$('div[aria-hidden=false] .slide-caption').removeClass('wow fadeIn');
.wow.fadeIn {
  color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="js-carousel u-carousel-v5"
             data-autoplay="true"
             data-infinite="true"
             data-fade="true"
             data-speed="4000">
<div class="js-slide g-bg-img-hero g-height-100vh--md g-min-height-300" aria-hidden="true" style="background-image: url(assets/img/1.jpg);">
        <h3 class="slide-caption wow fadeIn"  data-animation="animated fadeIn"  data-wow-delay="4s" >Image One</h3>
    </div>

    <div class="js-slide g-bg-img-hero g-height-100vh--md g-min-height-300" aria-hidden="true" style="background-image: url(assets/img/2.jpg);">
        <h3 class="slide-caption wow fadeIn"  data-animation="animated fadeIn"  data-wow-delay="4s" >Image Two</h3>
    </div>
    
    <div class="js-slide g-bg-img-hero g-height-100vh--md g-min-height-300" aria-hidden="false" style="background-image: url(assets/img/2.jpg);">
        <h3 class="slide-caption wow fadeIn"  data-animation="animated fadeIn"  data-wow-delay="4s" >Image Three</h3>
    </div>
</div>

关于javascript - 根据父元素属性更改元素的 CSS 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48004284/

相关文章:

javascript - django templatetags 用于 jquery 从 html templatetag 获取项目

javascript - 将单独的 CSS 和 JS 文件包含到标题中,或者将所有代码包含在一个 CSS 和一个 JS 文件中?

css - 如何使 svg 文本位置依赖于另一个文本位置?

javascript - 如何通过 Node JS 从 Python 调用并检索结果?

javascript - 切换 php 生成的 div 元素

javascript - 添加操作 woocommerce_add_to_cart 破坏网站原始添加到购物车功能

javascript - 分解为更小的功能 MVC

javascript - Lavalamp 菜单 - 未捕获的类型错误

html - 在 div 中居中图像而不裁剪图像和 overflow hidden

javascript - jQuery:改变最高值