我正在从头开始制作照片查看器,它工作正常,除了一些事情。
代码如下:
首先,我有当前相册的 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);
这是有效的,但我现在的问题是:
var cur_pic = 0; 设置为 0,意味着它将开始显示 json 数组中的第一张照片。我需要修复它,以便我可以在数组中找到我刚刚单击的照片的女巫编号,这样它就可以从那个位置开始查看和计数。
这现在只能在专辑中使用。假设我在另一页上可以看到一张照片。如何解决这个问题 - 当我点击它时 - 照片是可见的,我可以获得整个 json 数组,并浏览与我点击的照片属于同一相册的所有图像。
直接的例子。说 Facebook 或 Twitter。你在墙上有一张照片。单击它,您可以浏览整个专辑。
怎么解决?