我正在尝试使用Colorbox
从 facebook 填充的照片,这对于页面加载时填充的图像效果很好。但是当我使用.getJSON
加载 25 个以上的图像并将它们附加到我的表时,颜色框不再起作用。我已经看到提到使用该.live
命令,但我想我没有遵循该做什么......
这是我的jQuery代码
$(function () {
$(".photos1").colorbox({
rel: 'photos1',
transition: "fade"
});
var loading = '<img src="images/ajax-loader.gif" /> <b>LOADING</b>';
$('#get_albums').click(function () {
$('#ld_ck').html(loading);
$('#get_albums').html('');
load_albums();
});
$('#get_photos').click(function () {
$('#ld_ck').html(loading);
$('#get_photos').html('');
load_photos();
});
function load_photos() {
var after = $('#photos_next').val();
var offset = $('#photos_offset').val();
var gallery_id = $('#g_id').val();
$.getJSON('get_photos.php?gallery_id=' + gallery_id + '&after=' + after + '&offset=' + offset, function (json) {
$.each(json, function (key, val) {
if (key == "photos") {
$('#photos').append(val);
}
if (key == "after") {
$('#photos_next').val(val);
}
if (key == "offset") {
$('#photos_offset').val(val);
}
if (key == "count") {
if (val == "25") {
$('#get_photos').html('<b>SEE MORE</b>');
}
}
});
$('#ld_ck').html('');
});
}
});
get_photos.php
将json
一串表行返回到 jquery。
这里只是基本 html 表的一行,但最初有 5 行,并且get_photos.php
一次添加另外 5行
<table width="99%" border="0" cellspacing="5" cellpadding="0" id="photos" class="photos">
<tr>
<td align="center" class="photos" style="padding-top:10px; height:140px; width:140px; border:1px solid #7B7B7B; background:#E9E9E9;"><a class="photos1" href="fb_photo.jpg"> <img src="fb_thumb.jpg" alt="fb_photo" border="0" /> </a> </td>
<td align="center" class="photos" style="padding-top:10px; height:140px; width:140px; border:1px solid #7B7B7B; background:#E9E9E9;"><a class="photos1" href="fb_photo.jpg"> <img src="fb_thumb.jpg" alt="fb_photo" border="0" /> </a> </td>
<td align="center" class="photos" style="padding-top:10px; height:140px; width:140px; border:1px solid #7B7B7B; background:#E9E9E9;"><a class="photos1" href="fb_photo.jpg"> <img src="fb_thumb.jpg" alt="fb_photo" border="0" /> </a> </td>
<td align="center" class="photos" style="padding-top:10px; height:140px; width:140px; border:1px solid #7B7B7B; background:#E9E9E9;"><a class="photos1" href="fb_photo.jpg"> <img src="fb_thumb.jpg" alt="fb_photo" border="0" /> </a> </td>
<td align="center" class="photos" style="padding-top:10px; height:140px; width:140px; border:1px solid #7B7B7B; background:#E9E9E9;"><a class="photos1" href="fb_photo.jpg"> <img src="fb_thumb.jpg" alt="fb_photo" border="0" /> </a> </td>
</tr>
</table>
<div style="width:99%; text-align:center;" id="see_more">
<input name="photos_next" id="photos_next" type="hidden" value="xxxxxxxxxxxx" />
<input name="photos_offset" id="photos_offset" type="hidden" value="25" />
<input name="g_id" id="g_id" type="hidden" value="xxxxxxxx" />
<a id="get_photos"><b>SEE MORE</b></a></div>
<div id="ld_ck" class="loader" style="width:99%; text-align:center;" ></div>