当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js 加载时自动调整图片大小

Javascript
java编程教程:JDBC技术简介
浅析Ajax为什么优于JSF
JDK5.0中collection都有哪些变化
对性能和可扩展产生深远影响的J2EE
HTTP消息头字段深入介绍
java教程:网站开发中的入侵问题检测
简要介绍实现多线程环形缓冲的方法
DOM文档如何与XML文件互换?
Java教程:如何实现FTP功能
Bing API的简单了解
Javascript对网页输入框的字数限制
建立支持移动设备访问的网站sitemap
window.onload和body onload
JS教程:window.event对象
网页漂浮广告的关闭的实现代码
JavaScript教程:网页浮动定位提示效果
常用的Javascript代码高亮脚本
滑动导航菜单的变体使用
解决AJAX中文回传乱码
Javascript开发是否预留退路?

Javascript 中的 js 加载时自动调整图片大小


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

又一个javascript自动调整图片大小的脚本 // 方法:setSelectReadOnly 用于设定极select控件ReadOnly,
// 这个一个模拟只读不是真的只读
// 使用了onbeforeactivate,onfocus,onmouseover,onmouseout事件
// 示例:< img src='img.jpg' onload='ImgAutoSize(ImgD,FitWidth,FitHeight)' > ;
// create by sl
// ---------------------------------------------------
function ImgAutoSize(imgD,FitWidth,FitHeight)
{
var image1=new Image();
image1.onload = function ()
{
if(this.width>0 && this.height>0)
{
if(this.width/this.height>= FitWidth/FitHeight)
{
if(this.width>FitWidth)
{
imgD.width=FitWidth;
imgD.height=(this.height*FitWidth)/this.width;
}
else
{
imgD.width=this.width;
imgD.height=this.height;
}
}
else
{
if(this.height>FitHeight)
{
imgD.height=FitHeight;
imgD.width=(this.width*FitHeight)/this.height;
}
else
{
imgD.width=this.width;
imgD.height=this.height;
}
}
}
image1 = null;
}
image1.src=imgD.src;
imgD.style.cursor = 'hand';
imgD.onclick= function(){openWin(this.src,'imgphoto',600,400)};
imgD.title = "点击在新窗口中查看原图";
}