gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:33:07 26 4
gpt4 key购买 nike

我里面有几张图片<a>已绑定(bind)其点击以获取 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();
}

关于javascript - Photoswipe 在每个备用触发器上打开错误的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56226530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com