我们在首页提缩略图的时候会遇到有的是800×600图片还有600×800图片,如果我们把缩略图大小设置成固定大小,其中肯定有一个图会变形,下面代码可以帮你解决这个问题。
下面代码可以加到网页的任何位置:
Quote:
<script language="JavaScript">
var flag=false;
function DrawImage(ImgD,imageWidth,imageHeight) {
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= imageWidth/imageHeight){
if(image.width>imageWidth){
ImgD.width=imageWidth;
ImgD.height=(image.height*imageWidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>imageHeight){
ImgD.height=imageHeight;
ImgD.width=(image.width*imageHeight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
</script>
下面代码是图片设置:
<img src="<%=rs("pic")%>" border="0" />
0
顶一下0
踩一下