2012-02-17 51 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);