2012-02-17 69 views
3

我有我的页面上PhotoSwipe画廊这是编程创建这样的:在PhotoSwipe画廊更换图片

var instance = window.Code.PhotoSwipe.attach(image, options) 

现在我想在画廊更新图像,或换上新的画廊在同一地点。

创建为同一DOM Element一个新画廊忽略了以下错误:

Code.PhotoSwipe.activateInstance: 
Unable to active instance as another instance is already active for this target 

拆卸使用Code.PhotoSwipe.detatch(instance)没有帮助的元素的实例。

任何想法如何,以填补新图像画廊,或将其删除,这样我就可以建立在同一个地方一个新的?

+0

你好,我想要做的正是这一点。当用户滑动到下一张图像时,我希望它刷新图库,因为图像在滑动时被添加到DOM。我正在努力做到!你有没有设法做到底?有什么建议么?谢谢。 – 2012-05-12 16:54:22

+0

我面临着同样的问题。想要更新图库并在初始化后切换出一些图像。你们有没有想过这个?我无法分离并重新创建实例,因为这对用户是可见的。 – 2012-10-26 22:11:22

回答

8

我发现,以避免错误在呼唤unsetActivateInstance之前detatch的唯一方法:通过调用

window.Code.PhotoSwipe.activeInstances[0].instance.hide(0) 
2

,你也可以隐藏当前的活动实例,而不是detatching它的所有上述建议,但没有一个效果很好。

所以我的解决办法是根本不会创造同样的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); 
    } 
0

我试图

window.Code.PhotoSwipe.unsetActivateInstance(instance); 

window.Code.PhotoSwipe.detatch(instance);