【问题标题】:lightGallery in dynamic mode: incorrect image is loading when clicked动态模式下的 lightGallery:单击时加载的图像不正确
【发布时间】:2016-06-13 12:44:23
【问题描述】:

当我动态设置我的 lightGallery,并使用“索引”来定位点击链接时应打开的图像时,除非是第一次点击,否则会显示错误的图像。

换句话说,如果您最初单击缩略图,您会看到在弹出的图库中选择了正确的较大图像。但是,如果您随后关闭该图像,然后单击不同的缩略图图像,您将看到错误的图像被放大(它正在抓取您单击的第一个图像)。我认为这一定与“索引”功能在第一次点击后卡住有关?

我创建了一个 jsfiddle 来演示这个问题(对所有嵌套的 DIV 等表示歉意,但我相信这不是原因):http://jsfiddle.net/fcdeLd03/18/

有人有什么想法吗?

这是我启动 lig​​htGallery 的 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
        });
   });

【问题讨论】:

    标签: javascript jquery image dynamic lightgallery


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 2021-01-29
      相关资源
      最近更新 更多