admin管理员组文章数量:1297016
Hi how can I get the current slide no when I click next and previous button in GLide.js .html#intro.
var carousel = $('#Carousel').glide({
type: 'carousel',
startAt: 1,
touchDistance: 2,
afterInit:function(){console.log("paintSlider")},
autoplay: 0
});
console.log(carousel.current());
Hi how can I get the current slide no when I click next and previous button in GLide.js http://glide.jedrzejchalubek./docs.html#intro.
var carousel = $('#Carousel').glide({
type: 'carousel',
startAt: 1,
touchDistance: 2,
afterInit:function(){console.log("paintSlider")},
autoplay: 0
});
console.log(carousel.current());
Share
edited Apr 12, 2018 at 13:27
Jędrzej Chałubek
1,4481 gold badge16 silver badges29 bronze badges
asked Mar 7, 2016 at 6:32
Amila IddamalgodaAmila Iddamalgoda
4,29612 gold badges50 silver badges86 bronze badges
7 Answers
Reset to default 3 const glide = new Glide('.glide');
glide.on(['mount.after', 'run'], () => {
const currentIndex = glide.index;
console.log(currentIndex)
});
glide.mount();
For some reason, the function carousel.current()
is not working.
You can use the code's callback and events instead. Example:
var carousel = $('#Carousel').glide({
type: 'carousel',
...
afterTransition : function(event) {
console.log(event.index); // the current slide number
}
});
Also, carousel.index()
works too!
Not sure why, but documentation about accessing API is missing. I'll fix that.
You need to access api via .data('glide_api')
, before making api calls.
var carousel = $('#Carousel').glide({
type: 'carousel',
startAt: 1,
touchDistance: 2,
afterInit:function(){console.log("paintSlider")},
autoplay: 0
}).data('glide_api');
console.log(carousel.current());
Thanks for using plugin!
It works for me:
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()
});
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);
});
本文标签: javascriptHow to get the current slide no in GlidejsStack Overflow
版权声明:本文标题:javascript - How to get the current slide no in Glide.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741629578a2389282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论