首先,我要提到的是,我浏览了无数的问题和答案,其中许多似乎在逻辑上是可行的。
我对slimbox和AJAX有个问题。我正在执行一个简单的图像交换,当我这样做时,slimbox将不再适用于新添加的图像。
我尝试了很多事情,从调用Live (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>交换操作很好,图像也会发生变化。最大的问题是,我怎样才能确保把这张照片和减肥盒联系起来。
我尝试过的几件事是(不限于!):
在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
}
});我也尝试过在我的页面中插入代码来尝试类似的事情。
有人有什么建议吗?
发布于 2011-05-22 22:38:41
嗯,我继续努力解决这个问题,发现我做错了什么。AJAX如何更新页面的流程中的一个核心误解。我在AJAX代码中将slimbox调用插入到下面的函数中,现在它开始工作了!
function stateChanged() {
if (xmlHttp.readyState==4){
var product_color_image=xmlHttp.responseText;
if(product_color_image!=''){
document.getElementById('productMainImage').innerHTML = product_color_image;
}
$("a[rel^='lightbox']").slimbox({
<?php require_once(DIR_FS_CATALOG . DIR_WS_CLASSES . 'zen_lightbox/options.php'); ?>
}, function(el){
return [el.href, el.title /* + '<br /><a href="' + el.href + '">Download this image</a>'*/];
}, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
}), function() {
//remove slimbox? this is called when elements no longer match
}
}
}我需要研究一些更精细的细节,但至少现在,在对主产品映像执行AJAX交换之后,我的图像显示在一个照明盒中。
https://stackoverflow.com/questions/6087837
复制相似问题