替换 PhotoSwipe 库中的图像
我的页面上有一个 PhotoSwipe 画廊,它是以编程方式创建的,如下所示:
var instance = window.Code.PhotoSwipe.attach(image, options)
现在我想更新画廊,或在同一位置放置一个新画廊。
为同一 DOM 元素
创建新图库会忽略以下错误:
Code.PhotoSwipe.activateInstance:
Unable to active instance as another instance is already active for this target
使用 Code.PhotoSwipe.detatch(instance)
将实例与元素分离也没有帮助。
有什么想法如何用新图像填充图库或将其删除,以便我可以在同一位置创建新图像吗?
I have a PhotoSwipe gallery on my page which is created programatically like this:
var instance = window.Code.PhotoSwipe.attach(image, options)
Now I want to update the images in the gallery, or put a new gallery in the same spot.
Creating a new gallery for the same DOM Element
omits the following error:
Code.PhotoSwipe.activateInstance:
Unable to active instance as another instance is already active for this target
Detaching the instance from the Element using Code.PhotoSwipe.detatch(instance)
didn't help either.
Any ideas how to fill the gallery with new images, or remove it, so I can create a new one in the same place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现避免该错误的唯一方法是在
detatch
之前调用unsetActivateInstance
:The only way I found to avoid that error was calling
unsetActivateInstance
beforedetatch
:您还可以隐藏当前活动实例,而不是通过调用将其分离
you can also hide the current active instance, instead of detatching it by calling
我尝试了上面所有的建议,但没有一个效果很好。
所以我的解决方案就是永远不要为同一个 ID 创建图库两次:
I tried all the suggestions above but none of them worked well.
So my solution was to simply never create the gallery for the same ID twice: