3

嗨,当我单击 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());
4

6 回答 6

2

由于某种原因,该功能carousel.current()不起作用。

您可以改用代码的回调和事件。例子:

var carousel = $('#Carousel').glide({
            type: 'carousel',
            ...
            afterTransition : function(event) {
                console.log(event.index); // the current slide number
            } 
        });

另外,carousel.index()也有效!

于 2016-03-07T07:02:31.823 回答
2
 const glide = new Glide('.glide');

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

  glide.mount();
于 2020-01-03T03:35:56.927 回答
1

不知道为什么,但缺少有关访问 API 的文档。我会解决的。

.data('glide_api')在进行 api 调用之前,您需要通过 , 访问 api 。

var carousel = $('#Carousel').glide({
      type: 'carousel',
      startAt: 1,
      touchDistance: 2,
      afterInit:function(){console.log("paintSlider")},
      autoplay: 0
}).data('glide_api');

console.log(carousel.current());

感谢您使用插件!

于 2016-04-13T08:08:04.177 回答
0

这个对我有用:

jQuery(document).ready(function(){

    var glide = jQuery('.slider').glide({
        afterTransition : function() {
            console.log(glide.current());
        } 
    }).data('api_glide'); // data('api_glide') to get opportunity to use glide.current()

});
于 2016-09-07T12:21:55.897 回答
0

您可以访问indexglide 实例上的属性。

例如:

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 );
于 2020-11-26T12:51:30.043 回答
-1
const glide = new Glide('.glide');

glide.on("run", () => {
   console.log(slider.index);
});
于 2019-09-04T19:55:59.910 回答