lightGallery 动态模式不适用于 Firefox 和 Safari

lightGallery dynamic mode not working with Firefox and Safari

我将此代码设置为生成包含 34 张图像的图库:

$(document).ready(function (){
  $('#view-gallery').on('click', function() {
    $(this).lightGallery({
      dynamic: true,
      dynamicEl: [{
        "src": '../images/gallery/01_SL_01.jpg',
        'thumb': '../images/gallery/01_SL_01.jpg',
        'subHtml': "<div>Leather-bound miniature volume from an edition of The Merchant of Venice printed in the early 20th century to promote a chocolate company.<br/><em>Photo by Shane Lin.</em> </div>"
      }, {
        'src': '../images/gallery/02_UVALD_03.jpg',
        'thumb': '../images/gallery/02_UVALD_03.jpg',
        'subHtml': "<div>&quot;Hang there my verse, in witness of my love&quot;—page from an elaborately illustrated edition of <em>As You Like It: a Pleasant Comedy newly embellished with sundry decorations by W. H. Low</em> (1900). Low was a celebrated interior design artist who had decorated New York’s Waldorf Astoria.<br/><em>Image: UVA Library Digital Production Group.</em></div>"
      }, { 
      ...     
      }, {
        'src': '../images/gallery/34_SL_34.jpg',
        'thumb': '../images/gallery/34_SL_34.jpg',
        'subHtml': "<div>Minute page ornamentation from miniature volume of <em>Shakespeare’s Sonnets</em> (2000).<br/><em>Photo by Shane Lin.</em></div>"
      }]
    })
  });
});

当有人点击这个 link 时它会被调用: <div class="exhibit-link"><a id="view-gallery" href="">View Gallery</a></div>

但是 link 只适用于 Chrome。当在其他浏览器中单击时,画廊看起来会显示,因为有一段时间您可以看到第一张图像出现在叠加层中,但随后消失了。我在 lightGallery 文档中没有看到任何其他信息表明我在配置中遗漏了一些东西。但我想知道是否其他人可能已经看到了这个问题并找到了解决方案。谢谢

解决方案是确保浏览器不会尝试转到 href 位置,即使它是空的。空的 href 基本上会重新加载页面。将 link 代码更改为

<a id="view-gallery" href="javascript:void(0)">View Gallery</a>

阻止 Firefox 和 Safari 尝试重新加载页面。因此 onclick 事件被执行并起作用。