[javascript]代码库$("#pic_list ").on("click","img", function() {
var big_img_src = this.src.replace("small/","");
load_big_pic(big_img_src);
});
//图片等比自适应并居中
function load_big_pic(big_img_src) {
$('#big_img').attr('src',big_img_src);
var img = new Image();
img.src = big_img_src;
img.onload = function(){
var imgWidth ;
var imgHeight ;
imgWidth = this.width;
imgHeight = this.height;
if(imgWidth<1200 && imgHeight<400)
{
$("#big_img").width(imgWidth);
$("#big_img").height(imgHeight);
}
else
{
newWidth = 400*imgWidth/imgHeight;
$("#big_img").width(newWidth);
$("#big_img").height(400);
//让图片居中显示
var margin = (1200 - newWidth) / 2;
$("#big_img").css("margin-left", margin);
}
};
}