javascriptjquerycarouselswiper.jsglidejs

Get Current slide index with Glide.js


how can I get the current slide index/number when I swipe between elements with GLide.js

 const config = {
    type: "carousel",
    perView: 5,
    startAt: 2,
    perTouch: 1,
    focusAt: "center",
  };
  new Glide(".glide", config)
    .on("swipe.end", function (event) {
      console.log(event);
    })
    .mount();

Solution

  • Try using glide.index

    const config = {
      type: "carousel",
      perView: 5,
      startAt: 2,
      perTouch: 1,
      focusAt: "center",
    };
    
    var glide = new Glide(".glide", config)
    
    glide.on("swipe.end", function(event) {
      console.log('on swipe.end', glide.index)
    })
    
    glide.mount()
    
    console.log(glide.index)