2007-10-26
控制图片大小
关键字: 控制图片大小/*
控制图片大小
ImgD:类型为img的input元素对象,一般传入this即可
maxwidth:待显示的图片的最大宽度
maxheight:待显示的图片的最大高度
调用示例:
<input type="img" onload="DrawImage(this,80,80)"/>
*/
var flag=false;
function DrawImage(ImgD,maxwidth,maxheight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=maxwidth/maxheight){
if(image.width>maxwidth){
ImgD.width=maxwidth;
ImgD.height=(image.height*maxwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>maxheight){
ImgD.height=maxheight;
ImgD.width=(image.width*maxheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
- 11:22
- 浏览 (292)
- 评论 (0)
- 分类: javascript
- 相关推荐
发表评论
- 浏览: 17514 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
我的相册
2008-6-26
共 122 张
共 122 张
最近加入圈子
最新评论
-
创建XMLHttpRequest对象及 ...
返回XML文档 PrintWriter out = null; try ...
-- by weiweichen1985 -
存储过程的创建和调用。。 ...
嵌套循环 CREATE DEFINER=`root`@`localhost` ...
-- by weiweichen1985 -
js实现的年月日三级联动
日历来的更简洁,让用户操作三遍,不符合用户体验。
-- by igogo007 -
js实现的年月日三级联动
谢谢了,代码我收藏了啊
-- by hanhan7673 -
word提示用安全模式打开
...
-- by sunfengcheng






评论排行榜