首页 > 解决方案 > 使用 Glide.js 获取当前幻灯片索引

问题描述

当我使用 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();

标签: javascriptjquerycarouselswiperglidejs

解决方案


尝试使用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)

推荐阅读