按比例缩放图片的代码
2006-08-10 14:39
459 查看
<script language="JavaScript">
<!--
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>= 170/110){
if(image.width>170){
ImgD.width=170;
ImgD.height=(image.height*170)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
调用事例如:<IMG width=170 height=110 src='"&rs("IndexPicUrl")&"'onload='javascript:DrawImage(this);' border=0>
只需要改变你需要的图片大小即可宽度170,高度110
<!--
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>= 170/110){
if(image.width>170){
ImgD.width=170;
ImgD.height=(image.height*170)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
调用事例如:<IMG width=170 height=110 src='"&rs("IndexPicUrl")&"'onload='javascript:DrawImage(this);' border=0>
只需要改变你需要的图片大小即可宽度170,高度110
相关文章推荐
- php实现图片等比例缩放代码
- 等比例缩放图片代码
- JS实现按比例缩放图片的方法(附C#版代码)
- php等比例缩放图片及剪切图片代码分享
- javascript代码控制图片在页面显示时等比例缩放
- JS控制图片等比例缩放的示例代码
- Android ImageView图片代码实现按屏幕宽度等比例缩放
- JS实现按比例缩放图片的方法(附C#版代码)
- php图片缩放代码-按比例缩放或截取指定大小的缩略图 非常好用的一个方法
- javascript 指定区域内图片等比例缩放实现代码 脚本之家整合版 原创
- JS实现按比例缩放图片的方法(附C#版代码)
- 按比例缩放图片的js代码
- js 图片缩放(按比例)控制代码
- php实现图片等比例缩放代码
- js 图片等比例缩放代码
- PHP 等比例缩放图片详解及实例代码
- JS控制图片等比例缩放的示例代码
- javascript 指定区域内图片等比例缩放实现代码 脚本之家整合版 原创
- js 图片缩放(按比例)控制代码