收集于网络,自已小改动下。
有DrawImage(ImgD, width, height) 调整图像比例的javascript函数。
<script language="javascript">
<!--
var flag=false;
function DrawImage(ImgD, width, height){
var image=new Image();
var iwidth = width;
var iheight = height;
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
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>
<style type="text/css">
.pic_size {border:1px solid #CCCCCC;width:240px;height:200px;margin-top:5px;background:#FFF;}
</style>
<div class="pic_size"><table width="100%" height="100%"><tr><td style="text-align: center;vertical-align: middle;"><img src="my.jpg" onload = "DrawImage(this,240,200)"></td></tr></table></div>
posted on 2008-03-16 12:43
流浪汗 阅读(361)
评论(0) 编辑 收藏 所属分类:
HTML