当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 图片按比例缩放函数

Javascript
Prototype ObjectRange对象学习
Prototype Number对象 学习
Prototype Enumerable对象 学习
Prototype Template对象 学习
Prototype PeriodicalExecuter对象 学习
Prototype Array对象 学习
Prototype Hash对象 学习
[原创]IE view-source 无法查看看源码 JavaScript看网页源码
js计算页面刷新的次数
一个cssQuery对象 javascript脚本实现代码
一个可以随意添加多个序列的tag函数
javascript 三级下拉选择菜单Levels对象
JavaScript 进度条实现代码(Firefox等相似浏览器下不支持)
javascript 表单规则集合对象
从基础开始建立一个JS代码库
javascript Base类 包含基本的方法
js 代码集(学习js的朋友可以看下)
模仿jQuery each函数的链式调用
JavaScript 就地编辑HTML节点实现代码
JavaScript 动态生成方法的例子

Javascript 中的 图片按比例缩放函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 182 ::
收藏到网摘: n/a

以下是程序代码:
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
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="images/toplogo.gif" onload="javascript:DrawImage(this,100,100)">