Javascript 替换Photosweep库中的图像
我的页面上有一个图库,它是按如下程序创建的:Javascript 替换Photosweep库中的图像,javascript,photoswipe,Javascript,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 targe
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.photosweep.detatch(instance)
将实例从元素中分离也没有帮助
如何用新图像填充图库,或将其删除,以便我可以在同一位置创建新图像?我发现避免该错误的唯一方法是在detatch
之前调用unsetActivateInstance
:
window.Code.PhotoSwipe.unsetActivateInstance(instance);
window.Code.PhotoSwipe.detatch(instance);
您还可以隐藏当前活动实例,而不是通过调用
window.Code.PhotoSwipe.activeInstances[0].instance.hide(0)
我尝试了上面所有的建议,但没有一个效果好
因此,我的解决方案是永远不要为同一ID创建两次库:
instance = window.Code.PhotoSwipe.getInstance(myuniqueid);
if (window.Code.Util.isNothing(instance)) {
// Only initialize if there is no gallery with this ID already.
myPhotoSwipe = window.Code.PhotoSwipe.attach(window.document.querySelectorAll(galleryimagesselector), {captionAndToolbarAutoHideDelay: 0, jQueryMobile: true, preventSlideshow: true, enableMouseWheel: false, enableKeyboard: false}, myuniqueid);
}
你好,我想做的就是这个。我希望它在用户滑动到下一个图像时刷新图库,因为图像在滑动时被添加到DOM中。我正在努力做到这一点!你最终做到了吗?有什么建议吗?谢谢。我也面临着同样的问题。要更新库并在初始化后关闭一些图像。你们中有人知道这件事吗?我无法分离并重新创建该实例,因为该实例将对用户可见。