首先我會提到我瀏覽了無數的問題和答案,其中很多問題和答案在邏輯上看起來很有用。Jquery Slimbox和AJAX圖像交換問題
我遇到了slimbox和AJAX的問題。我正在執行一個簡單的圖像交換,當我這樣做時,slimbox將不適用於新添加的圖像。
我嘗試了很多事情從調用Live Query(jQuery插件)到簡單地嘗試重新綁定或重新調用slimbox。
任何幫助或建議將不勝感激。也許把我的確切場景放到上下文中會幫助解決已經存在的解決方案之一來解決我的問題。到目前爲止,我還沒有能夠加入它們。
第1步:我有我的PHP代碼生成我的網頁與主圖像,爲此slimbox的偉大工程:
<div id="productMainImage" class="centeredContent back">
<a href="images/large/redwhiteandyou_LRG.jpg" rel="lightbox-g" title="Red White and You"><img src="images/medium/redwhiteandyou_MED.jpg" alt="Red White and You" title=" Red White and You " width="250" height="167"><br><span class="imgLink">larger image</span></a>
</div>
第2步:我創建了一組屬性的圖像,其中我正在調用我的ajax代碼來進行圖像交換。這做一些處理,基本上設置#productmaainImage的innerhtml如下:
<div id="productMainImage" class="centeredContent back">
<a id="Yellow" href="images/large/attributes/redwhiteandyou_yellow_LRG.jpg" rel="lightbox-g" title="Yellow"><img src="images/medium/attributes/redwhiteandyou_yellow_MED.jpg" alt="Yellow" title=" Yellow " width="250" height="167"><br><span class="imgLink">larger image</span></a>
</div>
交換工作正常,圖像改變。最大的問題是我如何確保將該圖像與slimbox鏈接起來。
我試過一對夫婦的事情的東西(但不限於!):
插入由AJAX調用的代碼javascript寫出來的HTML:
$(document).ready(function() {
$('#content').find("a[rel^='lightbox']").slimbox({}, null, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
});
});
OR
$("a[rel^='lightbox']").livequery(function(){
$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
}), function() {
//remove slimbox? this is called when elements no longer match
}
});
我也嘗試在我的頁面插入代碼嘗試類似的事情。
任何人有任何建議嗎?