$( "#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); |
} |
}; |
} |
by: 发表于:2017-10-17 15:03:35 顶(0) | 踩(0) 回复
??
回复评论