<img src="wy_admin/<%=rs1("pic1")%>" width="220" height="150" border="0" ONLOAD='javascript:DrawImage(this);'>
必须要给初始文件大小
<script>
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var FitWidth=220;//图片的最大宽,超过这个值就会自动缩小
var FitHeight=150;//按比例缩小
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= FitWidth/FitHeight){
if(image.width>FitWidth){
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt="";
}
else{
if(image.height>FitHeight){
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt="";
}
}
}
</script>

本文介绍了一种通过JavaScript实现的图片自适应显示方法,确保图片能够在不同分辨率和屏幕尺寸下保持良好的视觉效果。该方法能够根据图片原始尺寸调整显示大小,避免失真。

1095

被折叠的 条评论
为什么被折叠?



