<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 1){
if(image.width>130){
ImgD.width=130;
ImgD.height=(image.height*130)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>130){
ImgD.height=130;
ImgD.width=(image.width*130)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
//-->
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 1){
if(image.width>130){
ImgD.width=130;
ImgD.height=(image.height*130)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>130){
ImgD.height=130;
ImgD.width=(image.width*130)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
//-->
本文介绍了一种网页中图片自适应显示的方法,确保图片无论在何种分辨率下都能保持良好的视觉效果。通过JavaScript动态调整图片大小,使图片宽度或高度不超过指定像素值,并保持原始宽高比不变。
288

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



