首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在“反应”中隐藏特定幻灯片的滑动分页?

如何在“反应”中隐藏特定幻灯片的滑动分页?
EN

Stack Overflow用户
提问于 2021-10-02 20:03:26
回答 1查看 2.2K关注 0票数 0

我有大约10个幻灯片在我的页面,它是完成使用反应刷。因此,我需要分页(在我的例子中,我使用了子弹)来隐藏幻灯片1和10。有办法隐藏那些使用js的人吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-07 19:11:11

一种解决办法。

使用swiper API

1/2.通过索引检测特定幻灯片

通过& slideChange事件检测 this幻灯片索引为0 (first slide),而不是做一些事情:

代码语言:javascript
复制
  swiper.on('paginationUpdate', function () {
    let realIndex = this.realIndex;
    if(realIndex == 0){
      console.log("hello first slide");
    }
  });

2/2.通过API:销毁/执行分页

swiper.pagination.init()

swiper.pagination.destroy()

代码语言:javascript
复制
  swiper.on('slideChange', function () {
    let realIndex = this.realIndex;
    if(realIndex == 0){
      /* Destroy pagination if slide is 1 */
      this.pagination.destroy();
    }else{
      /* Initialize pagination */
      this.pagination.init();     
    }
  });

演示示例(**在HTML中-但使用刷子反应的想法/概念):

代码语言:javascript
复制
const swiper = new Swiper('.swiper', {
    // Optional parameters
    loop: true,

    // If we need pagination
    pagination: {
      el: '.swiper-pagination',
    },

    // Navigation arrows
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    on: {
    init: function () {
      console.log('swiper initialized');
      /* hide pagination on load */
      this.pagination.destroy();
    }
  },
  });

  swiper.on('paginationUpdate', function () {
    let realIndex = this.realIndex;
    if(realIndex == 0){
      /* hide pagination if slide is 1 */
      this.pagination.destroy();
    }else{
      /* else show */
      this.pagination.init();     
    }
  });
代码语言:javascript
复制
html,
body {
  position: relative;
  height: 100%;
}

body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}

.swiper {
  width: 100%;
  height: 50%;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  /* Center slide text vertically */
  display: flex;
  justify-content: center;
  align-items: center;
}
代码语言:javascript
复制
<link
      rel="stylesheet"
      href="https://unpkg.com/swiper@7/swiper-bundle.min.css"
      />

<!-- Slider main container -->
<div class="swiper">
  <!-- Additional required wrapper -->
  <div class="swiper-wrapper">
    <!-- Slides -->
    <div class="swiper-slide">Slide 1 - Hide pagination</div>
    <div class="swiper-slide">Slide 2 - Show pagination</div>
    <div class="swiper-slide">Slide 3 - Show pagination</div>
    ...
  </div>
  <!-- If we need pagination -->
  <div class="swiper-pagination"></div>

  <!-- If we need navigation buttons -->
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>

</div>

<script src="https://unpkg.com/swiper@7/swiper-bundle.min.js"></script>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69419871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档