共享一个ASP里的图片自动缩放的JS
JS代码:
<script>
function zoomimg(ImgD,ImgW,ImgH)
{
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= ImgW/ImgH){
if(image.width>ImgW){
ImgD.width=ImgW;
ImgD.height=(image.height*ImgW)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
} else{
if(image.height>ImgH){
ImgD.height=ImgH;
ImgD.width=(image.width*ImgH)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
</script>
图片引用:
<img src="<%=Picfilepath%>" width="140" height="140" οnlοad="zoomimg(this,140,140)"》