首先,我要提到我浏览了无数的问题和答案,其中许多在逻辑上似乎可行。
我在使用 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 代码来进行图像交换。这做了一些处理,基本上将#productMainImage的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));
});
});
或者
$("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
}
});
我也尝试在我的页面中插入代码尝试类似的事情。
有人有什么建议吗?