javascript 实现图片按比例缩放
2011-07-23 18:03
567 查看
//图象按比例
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 80; //定义允许图片宽度
var iheight = 80; //定义允许图片高度
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>
<img src=".." onload = "DrawImage(this)">
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 80; //定义允许图片宽度
var iheight = 80; //定义允许图片高度
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>
<img src=".." onload = "DrawImage(this)">
相关文章推荐
- 用 JavaScript 实现网页图片等比例缩放
- 用 JavaScript 实现网页图片等比例缩放
- 用 JavaScript 实现网页图片等比例缩放效果
- 用JavaScript实现图片等比例缩放
- JavaScript实现网页图片等比例缩放
- javascript 实现网页图片等比例缩放
- 利用javascript实现图片等比例缩放
- javascript 指定区域内图片等比例缩放实现代码 脚本之家整合版 原创
- JavaScript实现网页图片等比例缩放实现代码及调用方式
- 用javascript实现图片等比例缩放
- javascript 指定区域内图片等比例缩放实现代码 脚本之家整合版 原创
- 用 JavaScript 实现网页图片等比例缩放
- 用 JavaScript 实现网页图片等比例缩放
- 用JavaScript实现网页图片等比例缩放
- 利用javascript实现图片等比例缩放
- <转>javascript实现图片的等比缩放
- 实现图片在控件中的按比例缩放方法
- PHP自定义图片缩放函数实现等比例不失真缩放的方法
- php实现等比例不失真缩放上传图片的方法