当我动态设置我的lightGallery时,使用'index'来定位单击链接时应打开的图像,除非是第一次点击,否则会显示错误的图像。
换句话说,如果您最初点击缩略图图像,则会在弹出的图库中看到正确选择的较大图像。但是,如果然后关闭该图像,然后单击另一个缩略图图像,您将看到错误的图像被放大(它抓住您点击的第一个图像)。我认为这必须与“索引”功能在第一次点击后卡住有关?
我已经创建了一个演示问题的jsfiddle(对所有嵌套DIV等道歉,但我确信这些不是原因):http://jsfiddle.net/fcdeLd03/18/
有人有什么想法吗?
这是我启动lightGallery的Javascript代码:
$(".nodoubt").on('click', function(){
var slideID = $(this).attr('data-slide');
$("#lightgallery").lightGallery({
download: false,
dynamic: true,
dynamicEl: [{
"src": 'http://sachinchoolur.github.io/lightGallery/static/img/1.jpg',
'thumb': 'http://sachinchoolur.github.io/lightGallery/static/img/thumb-1.jpg',
'subHtml': 'Photo 1 by <a href="http://www.example.com" target="_blank">Photographer Name</a><br />More caption text.<br />Even more caption text.'
},{
"src": 'http://sachinchoolur.github.io/lightGallery/static/img/2.jpg',
'thumb': 'http://sachinchoolur.github.io/lightGallery/static/img/thumb-2.jpg',
'subHtml': 'Photo 2 by <a href="http://www.example.com" target="_blank">Photographer Name</a><br />More caption text.<br />Even more caption text.'
},{
"src": 'http://sachinchoolur.github.io/lightGallery/static/img/3.jpg',
'thumb': 'http://sachinchoolur.github.io/lightGallery/static/img/thumb-3.jpg',
'subHtml': 'Photo 3 by <a href="http://www.example.com" target="_blank">Photographer Name</a><br />More caption text.<br />Even more caption text.'
},],
index : slideID
});
});
答案 0 :(得分:1)
/* for me helped */
<script type="text/javascript">
$(document).ready(function() {
$( "#pilt" ).click(function() {
var lGallery = $(this).lightGallery({
dynamic: true,
dynamicEl: [{___data___}]
});
/* open gallery on right image */
/* lightGallery parameter 'index' does not work */
lGallery.data('lightGallery').index = currentPage; /* page index you want to open */
})
});
</script>