javascript - 就像在滑动幻灯片中一样,仅为事件幻灯片创建事件链接?

标签 javascript jquery swiper.js

friend 们,请告诉我如何使链接处于事件状态,仅在事件幻灯片中?并在其他所有人中隐藏她。

https://codepen.io/Cheizer/pen/OJLWREZ

var s6 = new Swiper('.swiper-container', {
       spaceBetween: 10,
        slidesPerView: 'auto',
        slideToClickedSlide: true,
        navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
      pagination: {
    el: '.swiper-pagination',
    type: 'bullets',
         clickable: true,
  }, 
});

var el = $('.swiper-container .swiper-slide');

 $(el).each(function(i,el) {

if($(this).activeIndex){

$('a').show();

}else{

$('a').hide();

}

 });

这样做是行不通的:(

最佳答案

您可以在这里做两件事:

  1. CSS方式

    <style>
        .swiper-slide a {
            display:none
        }
        .swiper-slide.swiper-slide-active a {
          display:block
        }
    
    </style>
    
  2. JS方式

要查找哪张幻灯片已更改,您可以使用以下内容

mySwiper.on('slideChange', function () {
  console.log(mySwiper.realIndex, 'slide changed');
});

此时您所要做的就是更新该幻灯片内的元素并更新其他幻灯片以隐藏链接。 例如https://codepen.io/tsvecak/pen/abowYJW

关于javascript - 就像在滑动幻灯片中一样,仅为事件幻灯片创建事件链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57710504/

相关文章:

javascript - Swiper spaceBetween 无法正常工作

javascript - 当我隐藏/显示 swiper DOM 时,使用 .update() 和 .star Autoplay() 无法使其自动播放

javascript - typescript 中的原型(prototype) :Element implicitly has an 'any' type because type '_BaseOption' has no index signature

javascript - 更改值时未触发 $watch

javascript - 使用 $(document).ready() 和 $.getScript() 在页面完成加载后加载外部脚本

jquery - 使用 jQuery 设置 id

javascript - 如何在 Angular 中使用 Swiperjs CDN?

javascript - CSS : Justify dynamically created divs with variable width inside parent

javascript - 检查一个数组是否包含 JavaScript 中另一个数组的任何元素

javascript - 如何使用 Bootstrap Toggle 插件创建切换按钮?