Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

javascript - 如何检查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的文档)

  ask by abdoutelb translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ,依此类推。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...