简体   繁体   English

如何检查lightgallery.js的最后一张图片或最后一张幻灯片

[英]How check the last image or last slide of lightgallery.js

I am trying to check in any slide event the last image of the slider or even the slider length so i can calculate difference between current index and full length. 我正在尝试在任何幻灯片事件中检查滑块的最后一个图像,甚至滑块长度,以便我可以计算当前索引和全长之间的差异。

This is the documentation for LightGallery 这是LightGallery的文档

Here is a code that works! 这是一个有效的代码! I tested it on https://sachinchoolur.github.io/lightgallery.js/demos/ 我在https://sachinchoolur.github.io/lightgallery.js/demos/上进行了测试


lg = document.getElementById('aniimated-thumbnials');

lg.addEventListener('onAfterSlide', function(event){
  if (event.detail.index == (window.lgData.lg0.items.length - 1)) {
    alert("This is the Last Slide!");
  }
}, false);

lightGallery(lg);

In this code, change the following names/variables: 在此代码中,更改以下名称/变量:

aniimated-thumbnials - ID of the LightGallery 动画的缩略图-LightGallery的 ID

window.lgData.lg0 - window.lgData holds data about all LightGallery on the web page. window.lgData.lg0 - window.lgData保存有关网页上所有LightGallery的数据。 So, first LightGallery is window.lgData.lg0 , second one is window.lgData.lg1 , and so on. 因此,第一个LightGallery是window.lgData.lg0 ,第二个是window.lgData.lg1 ,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM