方案一:
<html>
<body>
<script language="javas
function reImg(obj,iw,ih) {
/************{ Coded By Tean }************
Ver_2007.03.09
Function:
Adjust Images size autmatically
for products preview width fixed size
Parameters:
obj: assign the object to adjust
*************{ Coded By Tean }************/
var iwh=iw/ih;
var image=new Image();
image.src=obj.src;
var w=image.width,h=image.height,wh=w/h;
if(w<=0 || h<=0) return false;
if(wh>=iwh){
if(w>iw){
obj.width=iw;
obj.height=iw/wh;
}else{
obj.width=w;
obj.height=h;
}
}else{
if(h>ih){
obj.height=ih;
obj.width=ih*wh;
}else{
obj.width=w;
obj.height=h;
}
}
}
</script>
<table height="104" border="1" cellpadding="0">
<tr align="center" bgcolor="#00CCFF">
<td width="110"><img src="11.gif" width=100% height=100% on
<td width="110"><img src="12.gif" width=100% height=100% on
<td width="110"><img src="21.gif" width=100% height=100% on
</tr>
</table>
</body>
</html>
方案二:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>TEST</title>
<script>
function goImg(){
o = document.images
for(i=0;i<o.length;i++)
if(o[i].width>100 && o[i].id='aa') o[i].width=400
}
</script>
</head>
<body on
<img src="logo1.jpg" id="aa" width="180" >
<img src="logo2.jpg" id="aa" width="371">
</body>
</html>
<html>
<head>
<title></title>
<script language="javas
/*实现图片的按比例缩放*/
function DrawImage(ImgD, iwidth, iheight) {
var image = new Image();
image.src = ImgD.src;
if(image.width > 0 && image.height > 0){
if(image.width / image.height >= iwidth / iheight){
if(image.width > iwidth){
ImgD.width = iwidth;
ImgD.height = (image.height * iwidth) / image.width;
}
else{
ImgD.width = image.width;
ImgD.height = image.height;
}
// ImgD.alt = image.width + "×" + image.height;
}
else{
if(image.height > iheight){
ImgD.height = iheight;
ImgD.width = (image.width * iheight) / image.height;
}
else{
ImgD.width = image.width;
ImgD.height = image.height;
}
// ImgD.alt = image.width + "×" + image.height;
}
}
}
// ---------------------------------------
</script>
</head>
<body>
<img src="test/pic.jpg" on
</body>
</html>
评论