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

Javascript
JavaScript[对象.属性]集锦之五
JavaScript[对象.属性]集锦之六
JavaScript[对象.属性]集锦之七
JavaScript[对象.属性]集锦之八
JavaScript[对象.属性]集锦之九
JavaScript[对象.属性]集锦之十
javascript进行客户端数据的校验(1)
javascript进行客户端数据的校验(2)
用JavaScript实现变色背景和文字(2)
用JavaScript实现文件夹轻松加密
初学Javascript之cookie篇(1)
初学Javascript之cookie篇(2)
初学Javascript之cookie篇(3)
初学Javascript之cookie篇(4)
JavaScript学习:基础继承机制(1)
JavaScript学习:基础继承机制(2)
JavaScript对象与数组参考大全(1)
JavaScript对象与数组参考大全(2)
JavaScript对象与数组参考大全(3)
JavaScript对象与数组参考大全(4)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 168 ::
收藏到网摘: 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 = "点击在新窗口中查看原图";
}