我从头开始照片查看器,它工作正常,除了几件事情。需要在jQuery的/ json的照片查看器阵列的一些提示
的代码是这样的:
首先我目前专辑的ID,并打印所有属于该照片图像。然后,当用户点击图片,这种情况发生:
var loaded = [];
var albums = [];
var album_id = ALBUM ID
var cur_pic = 0;
var alb_name = '';
$('.photo').click(function(){
var cover_photo = $(this).attr('id').replace("911","");
albums[album_id] = [];
$('#photo_preview .pleft').html('<img src="'+cover_photo+'"/>');
$('#photo_preview').show();
$.ajax({
type: 'POST',
url: "photo_ajax.php",
dataType:'json',
data: 'action=get_info' + $('#aid').val().replace("aid",""),
success: function(data){
loaded[album_id] = true;
albums[album_id] = data;
$('#photo_preview .pleft').html('<img src="'+albums[album_id][0]['ImagePath']+'"/>'); // The first photo you click on, will be the first photo to see :)
$('#photo_preview').show();
}
})
// }
});
// Loading images and make them visible in the popup...
function loadNextImage(album_id, step){
function loadNextImage(album_id, step){
var next_pic = 0;
if(step == 0){
next_pic = 0;
}else if(step == 'next'){
next_pic = parseInt(cur_pic, 10)+1;
cur_pic = next_pic;
if(next_pic >= albums[album_id].length){
next_pic = 0;
}
}else{
next_pic = parseInt(cur_pic, 10)-1;
if(next_pic < 0){
next_pic = albums[album_id].length - 1;
}
}
cur_pic = next_pic;
$('#photo_preview .pleft').html('<img src="'+albums[album_id][next_pic]['ImagePath']+'"/>');
}
// Loading the next image in the JSON array...:
$(".preview_next").click(function(){
loadNextImage(album_id, 'next');
});
// Loading the previous image in the JSON array...:
$(".preview_prev").click(function(){
loadNextImage(album_id, 'prev');
});
在photo_ajax.php:
$i = 0; $album = array();
foreach($aImageInfo as $row){
$album[$i] = array();
$album[$i]['ImageID'] = $row['ImageID'];
$album[$i]['ImagePath'] = $row['ImagePath'];
$album[$i]['ImageDate'] = $row['ImageDate'];
$album[$i]['ImageDescription'] = $row['ImageDescription'];
$i++;
}
echo json_encode($album);
这是工作,但我的问题是,现在这个:
变种cur_pic = 0;设置为0,意味着它将开始显示json数组中的第一张照片。我需要修正它,以便我可以在阵列中找到我刚刚点击的照片中的女巫编号,因此可以从该位置开始查看并计数。
这现在只能在相册中使用。假设我在另一页上显示一张照片。如何解决这个问题 - 当我点击它 - 照片是可见的,我可以得到整个json数组,并浏览属于与我单击的照片相同的相册的所有图像。
直的例子。说Facebook或Twitter。你在墙上有一张照片。点击它,你可以浏览整个相册。
如何解决?
我弄清楚如何找到阵列中当前值的编号,所以现在我需要找到问题编号2的解决方案。 我使用了一个循环遍历数组,并在匹配时返回值图像上的ID。 – 2012-07-14 10:19:47