使用 javascript 函数 完美控制页面图片显示大小 By shawl.qiu 函数 fResizeImg(w, h, id) 功能说明: 1. 本函数实现了指定高宽度显示图片大小 2. 本函数实现了按比例显示指定的高宽度 3. 本函数实现了是否指定 id 进行操作, 若不指定 id, 默认为页面全部图片. 4. 本函数实现了自动添加单击事件 4.1 单击图片后弹出一个窗口显示图片 4.2 再单击弹出的窗口则关闭本窗口 5. 弹出窗口按图片大小居中显示 6. 完美支持 IE, Opera 浏览器, 但对 Firefox 支持不够完善(由于个人习惯, 鄙人不打算费精力去完善对 Firefox 的支持) 目录: 1. fResizeImg(w, h, id) 函数源码及调用演示 shawl.qiu 2006-10-27 http://blog.csdn.net/btbtd
<!---->
使用 javascript 函数 完美控制页面图片显示大小 By shawl.qiu
函数 fResizeImg(w, h, id) 功能说明:
1. 本函数实现了指定高宽度显示图片大小
2. 本函数实现了按比例显示指定的高宽度
3. 本函数实现了是否指定 id 进行操作, 若不指定 id, 默认为页面全部图片.
4. 本函数实现了自动添加单击事件
4.1 单击图片后弹出一个窗口显示图片
4.2 再单击弹出的窗口则关闭本窗口
5. 弹出窗口按图片大小居中显示
6. 完美支持 IE, Opera 浏览器, 但对 Firefox 支持不够完善(由于个人习惯, 鄙人不打算费精力去完善对 Firefox 的支持)
目录:
1. fResizeImg(w, h, id) 函数源码及调用演示
shawl.qiu
2006-10-27
<script type="text/javascript">
//<!---->
window.onload=function(){
fResizeImg(500, 500, 'img');
//fResizeImg(500, 500);
}
/*------------------------------------------------------*\
* Subject: 使用 javascript 函数 完美控制页面图片显示大小 By shawl.qiu
* 使用:
* --------------------------------------
* 1. Javascript 脚本块
* window.onload=function(){
* fResizeImg(500, 500, 'img');
* //fResizeImg(500, 500);
* }
*
* 2. html body 标签
* <body onload="fResizeImg(500, 500, 'textMain');">
* --------------------------------------
* 注: 必须在页面加载完毕后使用本函数(这是基本的客户端应用概念)
\*-------------------------------------------------------*/
//---------------------------------begin function fResizeImg();
function fResizeImg(w, h, id){
var img='';
var obj;
if(id==undefined)obj=document.images;
else obj=document.getElementById(id).getElementsByTagName('img');
for(var i=0; i<obj.length; i++){="" <br="">
img=obj[i];
if(img.width>w&&(img.height<img.width)){ <br="">
img.height=img.height-(img.height/(img.width/(img.width-w)))
img.width=w;
}else if(img.height>h&&(img.height>img.width)){
img.width=img.width-(img.width/(img.height/(img.height-h)))
img.height=h;
}
img.onclick=function(){
try{ imgPopup.close();} catch(e){}
imgPopup=open('#', 'imgurl', 'width=500, height=500, left='+(screen.availWidth-500)/2+
', top='+(screen.availHeight-500)/2)
imgPopup.document.write('<script>document.onclick=function(){ close();} /* 单击关闭窗口 */ <\/script>');
imgPopup.document.write(''+
'<script>'+
'var w, h;'+
'var img=document.images[0];'+
'if(navigator.appName=="Opera"){w=img.width+10; h=img.height+40} else {w=img.width+10; h=img.height+25};'+
'self.resizeTo(w, h);'+
'self.moveTo((screen.availWidth-img.width)/2,(screen.availHeight-img.height)/2)'+
'<\/script>'+
'<style>body{margin:0; padding:0;} .hd{visibility:hidden;}<\/style>');
imgPopup.document.write('ok
');
imgPopup.document.close();
imgPopup.focus();
}
} // shawl.qiu script
}
//---------------------------------end function fResizeImg();
//]]>
</script>
js 代码
- <script type="text/javascript">
-
- window.onload=function(){
- fResizeImg(500, 500, 'img');
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function fResizeImg(w, h, id){
- var img='';
- var obj;
- if(id==undefined)obj=document.images;
- else obj=document.getElementById(id).getElementsByTagName('img');
-
- for(var i=0; i<obj.length; i++){
- img=obj[i];
- if(img.width>w&&(img.height<img.width)){
- img.height=img.height-(img.height/(img.width/(img.width-w)))
- img.width=w;
- }else if(img.height>h&&(img.height>img.width)){
- img.width=img.width-(img.width/(img.height/(img.height-h)))
- img.height=h;
- }
-
- img.onclick=function(){
- try{ imgPopup.close();} catch(e){}
- imgPopup=open('#', 'imgurl', 'width=500, height=500, left='+(screen.availWidth-500)/2+
- ', top='+(screen.availHeight-500)/2)
- imgPopup.document.write('<script>document.onclick=function(){ close();} <\/script>');
-
- imgPopup.document.write('<img src="'+this.src+'"/>'+
- '<script>'+
- 'var w, h;'+
- 'var img=document.images[0];'+
- 'if(navigator.appName=="Opera"){w=img.width+10; h=img.height+40} else {w=img.width+10; h=img.height+25};'+
- 'self.resizeTo(w, h);'+
- 'self.moveTo((screen.availWidth-img.width)/2,(screen.availHeight-img.height)/2)'+
- '<\/script>'+
- '<style>body{margin:0; padding:0;} .hd{visibility:hidden;}<\/style>');
- imgPopup.document.write('<p class="hd">ok</p>');
- imgPopup.document.close();
- imgPopup.focus();
- }
- }
- }
-
-
- </script>
分享到:
相关推荐
javascript 简单高效判断数据类型 系列函数 By shawl.qiu
说明: 主要功能就是在线压缩, 解压缩... 这个程序是以 7-zip 的命令行版本为载体, 服务器不需要安装7-zip就可以使用本程序. <br>目前压缩格式支持: 7z, zip. 解压缩格式支持: 7z, zip, gzip, bzip2,...
js prototype 格式化数字 By shawl.qiu
编写纯 CSS 弹出菜单的原理及实现 By shawl.qiu
服务端 VBScript 与 JScript 几个相同特性的写法 By shawl.qiu
ASP 技巧一则之 简化创建关闭记录集对象并创建使用简单的MSSQL存储过程 By shawl.qiu 1. 建造 创建关闭记录集函数 2. 在MSSQL查询分析器中创建简单的MSSQL存储过程 3. 在ASP中应用步骤1,2 shawl.qiu 2006-8-...
By shawl.qiu 摘要: 本文演示了ASP服务端脚本的几个重要应用. 目录: 1. 遍历集合/对象 1.1 VBScript 遍历表单集合 1.2 JScript 遍历表单集合 2. 转变量值为变量, 并赋值 2.1 VBScript 转变量值为变量并...
不建议使用本函数 shawl.qiu 2006-09-06 http://blog.csdn.net/btbtd 主内容: 函数及应用函数随机显示100条记录 linenum 代码如下:<% dim rs, rNum dim temp set rs=createObject(“adodb....
广告时间: shawl.qiu C# CMS 系统 预计40天后开始编码, 现在逐步设计中, 免得到时求职说什么什么作品…唉. PS: 今天求职真是惨不忍睹, 谁要招网页相关的请联系 13435580019, 邱先生. 什么地方俺都去, ...
无限级菜单结构 与 列表框无限级联动, 类 XSelect by shawl.qiu 压缩包包含: XSelect v1.0, XMenu v1.3, Select v1.3.1, Menu v1.0.1 (带X的是单表, 不带X的是多表.)
披肩 Shawl是用于将任何程序作为Windows... 使用Windows sc命令进行更多控制: sc create my-app binPath= "C:/path/shawl.exe run -- C:/path/my-app.exe" 然后正常启动或配置服务: sc config my-app start= auto
高中英语单词天天记shawl素材
”””””””””””””””””””””””””””””””””””” ‘ ‘ subject : Asp 创建静态文件/HTML By Stabx ‘ ‘ writer : Stabx<shawl> ‘ ‘ blog : http://btbtd.exblog.jp/ ...