Photoswipe 在每个备用触发器上打开错误的图像

Photoswipe opening wrong image on every alternate trigger

我在 <a> 标签内有几张图片,它们的点击已被绑定以获得图片的正确索引以进行 photoswipe。问题是第一次点击图片打开了正确的图片,但第二次点击总是打开同一张图片。此模式继续,交替单击打开与前一个相同的图像。相关代码是-

var init_photoswipe = function(){
    var $index = parseInt($(this).attr("index"));
    console.log($index)
    var options = {index: $index};
    var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, photoswipe_items, options);
    gallery.init();
}

load_photoswipe_items();
$("#gallery").on("click", ".full-image", init_photoswipe)

其中load_photoswipe_items()只是设置了photoswipe_items的列表。我已经检查过索引是否正确,并且只被点击了一次。任何帮助将不胜感激

阻止按钮的默认行为解决了问题。代码是-

var init_photoswipe = function(e){
    e.preventDefault();
    var $index = parseInt($(this).attr("index"));
    var options = {index: $index};
    gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, photoswipe_items, options);
    gallery.init();
}