在当前幻灯片上添加属性(div)

时间:2018-10-10 04:08:16

标签: jquery swiper

我正在尝试制作可向幻灯片动态添加属性的幻灯片(swiper.js)。

当“ swiper-slide(div)”具有类名“ swiper-slide-active”时, 然后添加属性aria-hidden =“ false”。 其他则是aria-hidden =“ true”

这是我到目前为止尝试过的,但是没有用 https://jsfiddle.net/3rsp34mg/402/

<div class="swiper-container">
  <div class="swiper-wrapper">
    <div class="swiper-slide">
      Slide 1
    </div>
    <div class="swiper-slide">
      Slide 2
    </div>
    <div class="swiper-slide">
      Slide 3
    </div>
  </div>
</div>


<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>



var swiper = new Swiper('.swiper-container', {

  nextButton: '.swiper-button-next',
  prevButton: '.swiper-button-prev',
  spaceBetween: 30 
});



$('.swiper-container .swiper-slide').attr('aria-hidden', 'true')

$(function(){ 
    $('.swiper-container .swiper-slide').each(function(){
        if($(this).hasClass('swiper-slide-active')) {
            $(this).attr('aria-hidden', 'false')
        } 
    });
});  

0 个答案:

没有答案