All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
GridView,批量删除,自定义分页,定位页码_[Asp.Net教程]
在asp.net2.0中使用存储过程_.net资料_编程技术
ASP.NET技巧:获取数据行数据信息_.net资料_编程技术
javascript事件列表_JavaScript技术_编程技术
SQL,SERVER学习,太复杂了!_mssql学习_编程技术
确保PHP安全,不能违反的四条安全规则_php资料_编程技术
asp.net,操作xml_.net资料_编程技术
通过PHP和Sajax使用Ajax之javascript_php资料_编程技术
SQL,server2000简介_mssql学习_编程技术
2个页面间不通过Session与url的传值方式_[Asp.Net教程]
Reading number is top 10 pictures
中国文革时期的色情图片1
2012 national geographic daily picture1
The little woman's bright wire1
西方气质的东方美女2
Chinese paper-cut grilles art appreciation2
Extremely rare TianShan Mountains snow lotus1
Born After 90 Beijing sports university campus flower photos2
Absolutely shocked. National geographic 50 animal photographys2
Exquisite decoration is not paying too much3
云南大理的美女
Download software ranking
尖东毒玫瑰A
The Bermuda triangle3
Unix video tutorial10
WebService在.NET中的实战应用教学视频 → 第3集
C++编程教程第三版
Boxer's Top ten classic battle7
Tram sex maniac 2 (H) rar bag7
Ashlynn Video5
Ashlynn Video2
Tram sex maniac 2 (H) rar bag1
delv published in(发表于) 2013/12/31 6:40:54 Edit(编辑)
按比例微缩图片的一段小小的JS代码_JavaScript技术_编程技术

按比例微缩图片的一段小小的JS代码_JavaScript技术_编程技术

按比例微缩图片的一段小小的JS代码_JavaScript技术_编程技术-你的首页-uuhomepage.com







自己写的一个非常简单的图片微缩JS代码,当然网上有很多类似的代码,在此确实是献丑了。
主要方法写在SetImgSize.js里面 SetImgSize.js
1 //智能微缩图片JS方法
2 //参数:imgID(图片的标识ID)
3 //参数:maxWidth(图片的最大宽度,值为0则表示不限制宽度)
4 //参数:maxHeight(图片的最大高度,值为0则表示不限制高度)
5 function setImgSize(imgID,maxWidth,maxHeight)
6 {
7 var img = document.images[imgID];
8 if(maxWidth < 1)
9 {
10 if(img.height > maxHeight)
11 {
12 img.height = maxHeight;
13 }
14 return true;
15 }
16 if(maxHeight < 1)
17 {
18 if(img.width > maxWidth)
19 {
20 img.width = maxWidth;
21 }
22 return true;
23 }
24 if(img.height > maxHeight || img.width > maxWidth)
25 {
26 if((img.height / maxHeight) > (img.width / maxWidth))
27 {
28 img.height = maxHeight;
29 }
30 else
31 {
32 img.width = maxWidth;
33 }
34 return true;
35 }
36 } 功能实现原理是在图片加载完毕后(onload事件)用JS实现微缩。
下面是一个测试用的文件test.htm test.htm
1 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 http://www.w3.org/1999/xhtml" >
3
4 测试
5
6
7
8 限定了宽度150px
9
http://img.poco.cn/photo/20060602/972374149620060602140117_1.jpg" />
10
限定了高度150px
11
http://img.poco.cn/photo/20060602/972374149620060602140117_4.jpg" />
12
限定了高度150px、宽度150px
13
http://static.flickr.com/46/147572720_8b25471150_o.jpg" />
14
15 就写到这里了,呵呵,是不是很简单啊!




















添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.