How to get the current slide no in Glide.js

Viewed 6660

Hi how can I get the current slide no when I click next and previous button in GLide.js http://glide.jedrzejchalubek.com/docs.html#intro.

var carousel = $('#Carousel').glide({
                type: 'carousel',
                startAt: 1,
                touchDistance: 2,
          afterInit:function(){console.log("paintSlider")},
          autoplay: 0
              });
console.log(carousel.current());
7 Answers
 const glide = new Glide('.glide');

  glide.on(['mount.after', 'run'], () => {
    const currentIndex = glide.index;
    console.log(currentIndex)
   });

  glide.mount();

You can access the property index on your glide instance.

For example:

import Glide, { Controls } from '@glidejs/glide/dist/glide.modular.esm';

var glider = new Glide( el, options );

glider.mount( {
  Controls,
} );

// You can get the current index using glider.index;
console.log( glider.index );

Glibert answer works

var stGlide = new Glide(`.heroglide-${article.id}`, {
          type: 'carousel',
          animationDuration: 500,
          startAt: 1,
          perView: 1,
          peek: {
              before: 50,
              after: 50
          },
        //   afterTransition : function(event) {
        //     console.log("========transition",event.index); // the current slide number
        // } 
          }); 
          try{
         
          stGlide.on(['mount.after', 'run'], () => {
            const currentIndex = stGlide.index;
            console.log("====>index==>",currentIndex)
           
           });

         
            stGlide.mount();
          }
 

const glide = new Glide('.glide');

glide.on("run", () => {
   console.log(slider.index);
});
Related