进入旧版 | 服务项目 | 成功案例 | 联系方式 | 过客留言 | 友情链接
   
设为首页
加入收藏
联系我们
网站首页 | 新闻资讯 | 操作系统 | 办公软件 | 网络软件 | 工具软件 | 媒体动画 | 网页制作 | 网站开发 | 程序开发 | 平面设计
Photoshop视频教程 | Word入门 | Flash入门 | JScript | VBScript | ASP | PHP | ADO | 网页特效 | 3DS MAX6.0命令 | 系统进程
您当前的位置:GOODSGY电脑学习网 -> 网站开发 -> JavaScript -> 文章内容  
按比例微缩图片的一段小小的JS代码

        自己写的一个非常简单的图片微缩JS代码,当然网上有很多类似的代码,在此确实是献丑了。
         主要方法写在SetImgSize.js里面
http://www.blue1000.com/bkhtml/2006-10/none'; Code_Closed_Text_153844.style.display='none'; Code_Open_Image_153844.style.display='inline'; Code_Open_Text_153844.style.display='inline';" height=16 src="http://www.blue1000.com/upload/2006_10/061029104078291.gif" width=11 align=top>http://www.blue1000.com/bkhtml/2006-10/none'; Code_Open_Text_153844.style.display='none'; Code_Closed_Image_153844.style.display='inline'; Code_Closed_Text_153844.style.display='inline';" height=16 src="http://www.blue1000.com/upload/2006_10/061029104078292.gif" width=11 align=top>
<--Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> 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
http://www.blue1000.com/bkhtml/2006-10/none'; Code_Closed_Text_154020.style.display='none'; Code_Open_Image_154020.style.display='inline'; Code_Open_Text_154020.style.display='inline';" height=16 src="http://www.blue1000.com/upload/2006_10/061029104078291.gif" width=11 align=top>http://www.blue1000.com/bkhtml/2006-10/none'; Code_Open_Text_154020.style.display='none'; Code_Closed_Image_154020.style.display='inline'; Code_Closed_Text_154020.style.display='inline';" height=16 src="http://www.blue1000.com/upload/2006_10/061029104078292.gif" width=11 align=top>test.htm
         就写到这里了,呵呵,是不是很简单啊!
         源码下载 SetImgSize.rar

在百度中搜索:按比例微缩图片的一段小小的JS代码
在Google中搜索:按比例微缩图片的一段小小的JS代码
在Yahoo中搜索:按比例微缩图片的一段小小的JS代码

收藏到网摘:新浪VIVI 365key 我摘 POCO网摘 博采中心 YouNote 和讯网摘 天天收藏
[] [返回上一页] [打 印] [收 藏]

 相关文章    最新文章
· [图文] web标准化制作:利用CSS按比例缩小..
· 按比例微缩图片的一段小小的JS代码
 
· 用JS解决网站防挂iframe木马的方案
· 技巧 JavaScript常用判断函数
· IE浏览器中一个值得关注的JS问题
· 简易实现DIV圆角的JavaScript代码
· Javascript调用XML制作连动下拉框
· Javascript实现页内查找关键词实例
· JavaScript的系统函数学习
· JavaScript仿Windows关机效果
· javascript弹出窗口问题总结
· 在JS中使用RecordSet对象的GetRows方法

∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
站内搜索

精彩图文
  网站导航  
操作系统 办公软件 网络软件
Vista Windows2003 WindowsXP Windows2000/NT Windows9X/ME Linux 其他 Word Excel Powerpoint Outlook 金山系列 其他 网页浏览 上传下载 联络聊天 邮件工具 服务器软件 网络辅助
工具软件 媒体动画 网页制作
系统工具 媒体工具 压缩工具 图文处理 文件管理 其他 3DMAX Authorware Director Maya 视频处理 其他 Flash Dreamweaver FireWorks FrontPage LiveMotion Golive HTML/CSS 其它
网站开发 平面设计 程序设计
ASP JSP PHP CGI JavaScript VBScript XML/SOAP Web服务器 Photoshop PhotoImpact CorelDraw Illustrator Freehand 设计欣赏 其他 VB VC .NET C/C++ DELPHI JAVA

冀ICP备05019428号
Copyright © 2004-2008 电脑学习网 Inc.All rights reserved.
TEL:13832340607
QQ:39873155
E_Mail:goodsgy(#)hotmail.com   (把(#)替换成@)
MSN:goodsgy(#)hotmail.com   (把(#)替换成@)