question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get the current active slide index?

See original GitHub issue

i have this simple

  <swiper id="swiper-container" :options="swiperOption" @slideChange="runOnChange">
    <div class="swiper-pagination" slot="pagination" v-on:slide></div>
    <swiper-slide class="map">Slide 1</swiper-slide>
    <swiper-slide class="scan">Slide 2</swiper-slide>
    <swiper-slide class="info">Slide 3</swiper-slide>
  </swipedfdfr>

And I would like to get the current active slide.

But when I run on the swiperOption funciton mySwipe.activeIndex() I always get a 0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

19reactions
ybrochcommented, May 13, 2018

you can add a event then easy to get it on v3.1.3,like this: <swiper :options="swiperOption" @slideChange="changeSwiperIndex" ref="mySwiper">and set a mothods like thischangeSwiperIndex () { return this.$refs.mySwiper.swiper.activeIndex }

15reactions
AndiDomicommented, Apr 16, 2018

ok, it took a bit of time but in the end I made it work this is my final code if someone needs it

<template>
  <swiper :options="swiperOption" ref="mySwiper">
    <!-- slides -->
    <swiper-slide class="info" >I'm Slide 1</swiper-slide>
    <swiper-slide class="info">I'm Slide 2</swiper-slide>
    <swiper-slide class="info">I'm Slide 3</swiper-slide>
    <swiper-slide class="info">I'm Slide 4</swiper-slide>
    <swiper-slide class="info">I'm Slide 5</swiper-slide>
    <swiper-slide class="info">I'm Slide 6</swiper-slide>
    <swiper-slide class="info">I'm Slide 7</swiper-slide>
  </swiper>
</template>

<script>
  export default {
    name: 'carrousel',
    data(){
      const vue = this;
      return {
        swiperOption: {
          notNextTick: true,
          setWrapperSize :true,
          autoHeight: true,
          onSlideChangeEnd:function(){
            this.onSwipe()
          }
        }
      }
    },

    methods : {
      onSwipe(varuable) {
        console.log('Get ready to see the slide you are in')
        console.log(varuable.swiper.activeIndex);
      }
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper
    }
  },
  mounted() {
    console.log('this is current swiper instance object',this.swiper);
    console.log('active? ',this.swiper.activeIndex );
    this.swiper.on('slideChange',()=>{
      this.onSwipe(this)
    });

  }
  }
</script>

<style scoped>

  .info{
    margin-inside: 10px;
    height: 75vh;
    width:100%;
    background-color: yellow;
  }

</style>

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect current slide in swiper js? - Stack Overflow
idangero.us/swiper/api/#.VhJDi_mqpHw In this page we can use > mySwiper.activeIndex Index number of currently active slide Note, that in loop mode active index ......
Read more >
how to get current slide element index in swiper js react
With swiper.activeIndex you are accessing the virtual slides, just use swiper.realIndex for the real index. Open side panel.
Read more >
Using .last() to check if we're on the last slide - Codecademy
What I'd like to know though is if there is a way to use the jQuery method .last() to check if the current...
Read more >
Carousel issue : activeSlide doesnt work properly
Dear Szar, You can get index of current active slide by using ViewChildren decorator. Please check my code: .ts: import { Component, AfterContentChecked ......
Read more >
Swiper API
To get vanilla HTMLElement use swiper.wrapperEl. swiper.activeIndex, number. Index number of currently active slide. Note, that in loop mode active index ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found