- 浏览: 251379 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
wangyajin333:
太棒了。谢谢分享。
ajax提交编码转换问题 java.io.charConVersionException:EOF -
leon.s.kennedy:
security3.0 也是如此
spring Security 中角色名字必须满足ROLE_XXX的格式 -
CoderDream:
如果把工程源代码贴出了就更好了,可以不带jar档!
struts2中Spring Security 自定义登陆页面的实现 -
heyujunlikely:
String s = "/**** package ...
java 去除注释的正则表达式 -
hastenlife:
[i][/i][b][/b][u][/u]引用引用[url][ ...
struts2 Validator 整合freemarker 取得FieldError的方法
发布一个实用的js window封装类,主要内容包括:
1.获取屏幕宽度的函数
2.获取屏幕高度的函数
3.获取滚动条横向宽度
4.获取滚动条竖向高度
5.window.onscroll绑定事件
6.删除window.onscroll绑定事件
7.window.onload绑定事件
8.让元素显示在屏幕中间
9.获取屏幕中间显示距离顶部的高度
10.固顶元素在屏幕中显示,不随滚动条的变化而变化
- if(!coos)var coos = function(){};
- if(!coos.browser)
- {
- coos.userAgent = navigator.userAgent.toLowerCase();
- coos.browser = {
- version: (coos.userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
- safari: /webkit/.test(coos.userAgent),
- opera: /opera/.test(coos.userAgent),
- msie: /msie/.test(coos.userAgent) && !/opera/.test(coos.userAgent),
- mozilla: /mozilla/.test(coos.userAgent) && !/(compatible|webkit)/.test(coos.userAgent)
- };
- }
- coos.window = function(){};
- coos.window.winWidth = 0;
- coos.window.winHeight = 0;
- /**
- * 获取屏幕宽度的函数,在非xhtml标准页面下有可能有问题
- */
- coos.window.width = function()
- {
- if (window.innerWidth)//for Firefox
- {
- coos.window.winWidth = window.innerWidth;
- }
- else if((document.body) && (document.body.clientWidth))
- {
- coos.window.winWidth = document.body.clientWidth;
- }
- if (document.documentElement && document.documentElement.clientWidth)
- {
- coos.window.winWidth = document.documentElement.clientWidth;
- }
- return coos.window.winWidth;
- };
- /**
- * 获取屏幕高度的函数
- * html,body高度属性必须设值为height:100%否则在火狐浏览器下获取不到真实高度
- */
- coos.window.height = function()
- {
- if (window.innerHeight)//for Firefox
- {
- coos.window.winHeight = window.innerHeight;
- }
- else if((document.body) && (document.body.clientHeight))
- {
- coos.window.winHeight = document.body.clientHeight;
- }
- if (document.documentElement && document.documentElement.clientHeight)
- {
- coos.window.winHeight = document.documentElement.clientHeight;
- }
- return coos.window.winHeight;
- };
- /**
- * 获取滚动条横向宽度
- */
- coos.window.scrollWidth = function()
- {
- return document.body.scrollWidth + "px";
- };
- /**
- * 获取滚动条竖向高度,取body.scrollHeight和documentElement.scrollHeight中最高的一个
- */
- coos.window.scrollHeight = function()
- {
- return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight) + "px";
- };
- coos.window.onscroll = function(){};
- /**
- * window.onscroll绑定事件
- * @param fn 需要绑定的function
- */
- coos.window.onscroll.add = function(fn)
- {
- if (window.addEventListener)
- {
- window.addEventListener("scroll",fn,false);
- }
- else
- {
- window.attachEvent("onscroll", fn);
- }
- };
- /**
- * 删除window.onscroll绑定事件
- * @param fn 需要绑定的function
- */
- coos.window.onscroll.remove = function(fn)
- {
- if (window.removeEventListener)
- {
- window.addEventListener("scroll",fn,false);
- }
- else
- {
- window.detachEvent("onscroll", fn);
- }
- };
- /**
- * window.onload绑定事件
- * @param fn 需要绑定的function
- */
- coos.window.onload = function(fn)
- {
- if (window.addEventListener)
- {
- window.addEventListener("load",fn,false);
- }
- else
- {
- window.attachEvent("onload", fn);
- }
- };
- /**
- * 让元素显示在屏幕中间,元素必须是绝对定位的
- * @param obj 要显示的对象,改变top left 属性值
- * @param event 触发的事件,在有滚动条的情况下必须传入事件以获取当时所在的滚动条高度
- * @example
- <style type="text/css">
- html,body {margin: 0; padding: 0;height:100%;font-size: 14px;}
- </style>
- <script type="text/javascript">
- function show(event)
- {
- var obj = document.getElementById("showDiv");
- coos.window.center(obj,event);
- //元素在屏幕中间距离顶部的高度
- var top = coos.window.center.top(obj);
- //固顶在屏幕上,不随滚动条变化
- coos.window.fixed.set(obj,top);
- coos.window.fixed();
- }
- </script>
- <div id="showDiv" style="position:absolute;left:20px;top:5px;height:20px;width:400px;border:2px solid #ccc;text-align: center;clear: both;">
- I'm a div,I can show and fixed in center!
- </div>
- <div style="clear: both;margin:80px;height:1000px;">
- <br /><br />
- <a href="javascript:void(0)" onclick="show(event)">show div center</a>
- </div>
- */
- coos.window.center = function(obj,event)
- {
- var e = event || window.event;
- if(e)
- {
- obj.style.left = ((coos.window.width() - parseInt(obj.style.width,10))/2).toFixed() + "px";
- var objh = (parseInt(obj.style.height,10)/2).toFixed();
- var sh = parseInt(Math.max(document.body.scrollTop,document.documentElement.scrollTop),10);
- var wh = parseInt((coos.window.height()/2).toFixed(),10);
- var ch = sh + wh;
- obj.style.top = (ch - objh) + "px";
- }
- else
- {
- obj.style.left = ((coos.window.width() - parseInt(obj.style.width,10))/2).toFixed() + "px";
- obj.style.top = ((coos.window.height() - parseInt(obj.style.height,10))/2).toFixed() + "px";
- }
- };
- /**
- * 获取屏幕中间显示距离顶部的高度
- */
- coos.window.center.top = function(obj)
- {
- return ((coos.window.height() - parseInt(obj.style.height,10))/2).toFixed();
- };
- /**
- * 固顶元素在屏幕中显示,不随滚动条的变化而变化
- */
- coos.window.fixed = function()
- {
- coos.window.onscroll.add(coos.window.fixed.bind);
- };
- /**
- * 绑定需要固顶高度的元素window.onscroll事件
- */
- coos.window.fixed.bind = function()
- {
- if(!coos.window.fixed.obj || !coos.window.fixed.top)
- {
- return;
- }
- var objs = coos.window.fixed.obj;
- var tops = coos.window.fixed.top;
- var len = objs.length;
- //ie6.0以下不支持position:fixed;属性
- if(coos.browser.msie && parseInt(coos.browser.version) <= 6)
- {
- for(var i = 0; i < len;i++)
- {
- var sh = parseInt(Math.max(document.body.scrollTop,document.documentElement.scrollTop),10);
- objs[i].style.top = (sh + tops[i]) + "px";
- }
- }
- else
- {
- for(var i = 0; i < len;i++)
- {
- objs[i].style.position = "fixed";
- objs[i].style.top = tops[i] + "px";
- }
- //设置完position:fixed;属性和top属性后移除onscroll事件
- coos.window.onscroll.remove(coos.window.fixed.bind);
- }
- };
- /**
- * 设置需要固定高度的元素
- * @param obj 需要固定高度的元素对象
- * @param top 需要固定高度的元素距离顶部的高度
- */
- coos.window.fixed.set = function(obj,top)
- {
- if(!coos.window.fixed.obj)
- {
- coos.window.fixed.obj = new Array();
- }
- coos.window.fixed.obj.push(obj);
- if(!coos.window.fixed.top)
- {
- coos.window.fixed.top = new Array();
- }
- top = parseInt(top,10);
- coos.window.fixed.top.push(top);
- };
if(!coos)var coos = function(){}; if(!coos.browser) { coos.userAgent = navigator.userAgent.toLowerCase(); coos.browser = { version: (coos.userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1], safari: /webkit/.test(coos.userAgent), opera: /opera/.test(coos.userAgent), msie: /msie/.test(coos.userAgent) && !/opera/.test(coos.userAgent), mozilla: /mozilla/.test(coos.userAgent) && !/(compatible|webkit)/.test(coos.userAgent) }; } coos.window = function(){}; coos.window.winWidth = 0; coos.window.winHeight = 0; /** * 获取屏幕宽度的函数,在非xhtml标准页面下有可能有问题 */ coos.window.width = function() { if (window.innerWidth)//for Firefox { coos.window.winWidth = window.innerWidth; } else if((document.body) && (document.body.clientWidth)) { coos.window.winWidth = document.body.clientWidth; } if (document.documentElement && document.documentElement.clientWidth) { coos.window.winWidth = document.documentElement.clientWidth; } return coos.window.winWidth; }; /** * 获取屏幕高度的函数 * html,body高度属性必须设值为height:100%否则在火狐浏览器下获取不到真实高度 */ coos.window.height = function() { if (window.innerHeight)//for Firefox { coos.window.winHeight = window.innerHeight; } else if((document.body) && (document.body.clientHeight)) { coos.window.winHeight = document.body.clientHeight; } if (document.documentElement && document.documentElement.clientHeight) { coos.window.winHeight = document.documentElement.clientHeight; } return coos.window.winHeight; }; /** * 获取滚动条横向宽度 */ coos.window.scrollWidth = function() { return document.body.scrollWidth + "px"; }; /** * 获取滚动条竖向高度,取body.scrollHeight和documentElement.scrollHeight中最高的一个 */ coos.window.scrollHeight = function() { return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight) + "px"; }; coos.window.onscroll = function(){}; /** * window.onscroll绑定事件 * @param fn 需要绑定的function */ coos.window.onscroll.add = function(fn) { if (window.addEventListener) { window.addEventListener("scroll",fn,false); } else { window.attachEvent("onscroll", fn); } }; /** * 删除window.onscroll绑定事件 * @param fn 需要绑定的function */ coos.window.onscroll.remove = function(fn) { if (window.removeEventListener) { window.addEventListener("scroll",fn,false); } else { window.detachEvent("onscroll", fn); } }; /** * window.onload绑定事件 * @param fn 需要绑定的function */ coos.window.onload = function(fn) { if (window.addEventListener) { window.addEventListener("load",fn,false); } else { window.attachEvent("onload", fn); } }; /** * 让元素显示在屏幕中间,元素必须是绝对定位的 * @param obj 要显示的对象,改变top left 属性值 * @param event 触发的事件,在有滚动条的情况下必须传入事件以获取当时所在的滚动条高度 * @example <style type="text/css"> html,body {margin: 0; padding: 0;height:100%;font-size: 14px;} </style> <script type="text/javascript"> function show(event) { var obj = document.getElementById("showDiv"); coos.window.center(obj,event); //元素在屏幕中间距离顶部的高度 var top = coos.window.center.top(obj); //固顶在屏幕上,不随滚动条变化 coos.window.fixed.set(obj,top); coos.window.fixed(); } </script> <div id="showDiv" style="position:absolute;left:20px;top:5px;height:20px;width:400px;border:2px solid #ccc;text-align: center;clear: both;"> I'm a div,I can show and fixed in center! </div> <div style="clear: both;margin:80px;height:1000px;"> <br /><br /> <a href="javascript:void(0)" onclick="show(event)">show div center</a> </div> */ coos.window.center = function(obj,event) { var e = event || window.event; if(e) { obj.style.left = ((coos.window.width() - parseInt(obj.style.width,10))/2).toFixed() + "px"; var objh = (parseInt(obj.style.height,10)/2).toFixed(); var sh = parseInt(Math.max(document.body.scrollTop,document.documentElement.scrollTop),10); var wh = parseInt((coos.window.height()/2).toFixed(),10); var ch = sh + wh; obj.style.top = (ch - objh) + "px"; } else { obj.style.left = ((coos.window.width() - parseInt(obj.style.width,10))/2).toFixed() + "px"; obj.style.top = ((coos.window.height() - parseInt(obj.style.height,10))/2).toFixed() + "px"; } }; /** * 获取屏幕中间显示距离顶部的高度 */ coos.window.center.top = function(obj) { return ((coos.window.height() - parseInt(obj.style.height,10))/2).toFixed(); }; /** * 固顶元素在屏幕中显示,不随滚动条的变化而变化 */ coos.window.fixed = function() { coos.window.onscroll.add(coos.window.fixed.bind); }; /** * 绑定需要固顶高度的元素window.onscroll事件 */ coos.window.fixed.bind = function() { if(!coos.window.fixed.obj || !coos.window.fixed.top) { return; } var objs = coos.window.fixed.obj; var tops = coos.window.fixed.top; var len = objs.length; //ie6.0以下不支持position:fixed;属性 if(coos.browser.msie && parseInt(coos.browser.version) <= 6) { for(var i = 0; i < len;i++) { var sh = parseInt(Math.max(document.body.scrollTop,document.documentElement.scrollTop),10); objs[i].style.top = (sh + tops[i]) + "px"; } } else { for(var i = 0; i < len;i++) { objs[i].style.position = "fixed"; objs[i].style.top = tops[i] + "px"; } //设置完position:fixed;属性和top属性后移除onscroll事件 coos.window.onscroll.remove(coos.window.fixed.bind); } }; /** * 设置需要固定高度的元素 * @param obj 需要固定高度的元素对象 * @param top 需要固定高度的元素距离顶部的高度 */ coos.window.fixed.set = function(obj,top) { if(!coos.window.fixed.obj) { coos.window.fixed.obj = new Array(); } coos.window.fixed.obj.push(obj); if(!coos.window.fixed.top) { coos.window.fixed.top = new Array(); } top = parseInt(top,10); coos.window.fixed.top.push(top); };
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>coos.extend.window Build Test Page</title>
- <script type="text/javascript" src="coos.extend.window.js"></script>
- </head>
- <body>
- <style type="text/css">
- html,body {margin: 0; padding: 0;height:100%;font-size: 14px;}
- </style>
- <script type="text/javascript">
- function show(event)
- {
- var obj = document.getElementById("showDiv");
- coos.window.center(obj,event);
- //元素在屏幕中间距离顶部的高度
- var top = coos.window.center.top(obj);
- //固顶在屏幕上,不随滚动条变化
- coos.window.fixed.set(obj,top);
- coos.window.fixed();
- }
- </script>
- <div id="showDiv" style="position:absolute;left:20px;top:5px;height:20px;width:400px;border:2px solid #ccc;text-align: center;clear: both;">
- I'm a div,I can show and fixed in center!
- </div>
- <div style="clear: both;margin:80px;height:1000px;">
- <br /><br />
- <a href="javascript:void(0)" onclick="show(event)">show div center</a>
- </div>
- </body>
- </html>
- coos_window_test.rar (2.8 KB)
- 下载次数: 14
发表评论
-
coos.$script 动态插入脚本并执行的方法
2010-08-23 16:59 1829/** * 动态插入脚本并执行 * ... -
终于完成coos的重构了
2010-02-07 18:01 977考虑到大部分人不一定使用java或ssh开发,已经去掉ssh框 ... -
发布一个最新版coos核心代码
2009-08-10 10:49 2238发布一个最新版coos核心 ... -
ajax中post的escape扩展方法
2009-07-29 18:47 1458ajax中post的escape对有些特殊字符无法转换,例如: ... -
ajax中post的escape扩展方法
2009-07-24 14:09 1406ajax中post的escape对有些特殊字符无法转换,例如: ... -
发布一个实用的js window封装类
2009-07-23 19:02 1766发布一个实用的js window封装类,主要内容包括: 1. ... -
coos脚本库说明
2009-07-02 11:43 1330coos脚本库说明 coos(commo ...
相关推荐
NULL 博文链接:https://zdz8207.iteye.com/blog/431813
里面有较多的JS封装类,比如数组类,可在数组中的每个项上运行一个函数,并将全部结果作为数组返回,也可在在数组中的每个项上运行一个函数,并将函数返回真值的项作为数组返回;浏览器兼容性测试类,包括检测js的...
EXTJS的组件体系由Component类定义,每一种组件都有一个指定的xtype属性值,通过该值可以得到一个组件的类型或者是定义一个指定类型的组件。EXTJS的组件体系可以分成三大类,即基本组件、工具栏组件、表单及元素组件...
if (window.ActiveXObject){isIE=true;}else{isIE=false;} var node_xml; var xmlDoc; if (isIE){ xmlDoc = new ActiveXObject(“Msxml2.DOMDocument”); } else{ if (document.implementation && document....
7.3.1 构造函数--一个双精度浮点数封装类的例子 7.3.2 缺省构造和拷贝构造 7.3.3 对象常量 7.4 对象的销毁和存储单元的回收 7.5 JavaScript的内置对象 7.5.1 Math对象 7.5.2 Date对象--...
这里介绍了chooseCancelOnNextConfirmation、chooseOkOnNextConfirmation等JavaScript脚本实现的弹出窗口处理函数,selenium会弹出网页窗口,因为它重写了window.open在文件selenium-browserbot.js函数BrowserBot....
jObject.js是一个简单JavaScript API,可帮助用户轻松快捷地开发Web应用程序客户端。 它提供CSS操作,支持按类获取元素,包括事件处理,表单验证,简化的AJAX,优美的ModalWindow,日历,计时器以及一些系统支持功能...
iejoyswebos for .net 桌面开发框架程序是一个仿Window Vista的Web桌面开发系统 建议使用IE7或火狐浏览器! 本程序使用了EXTJS3.3最新版本!并对EXTJS中原有的一些不适合大型项目使用的方法进行了改写,具体有: 1...
JavaScript中BOM和DOM详解 目录 BOM(浏览器对象模型) 1. window 获取浏览器c窗口尺寸 2. screen 获取电脑屏幕大小 3. window 开启关闭窗口 4. 浏览器事件 5. location 6. history 7. navigator 获取浏览器相关...
mxp/在代码编辑框中选择一段脚本代码,然后使用这个插件,可以把这些代码放到一个单独的js文件中 mxp/在Dreamweaver中快速的插入一个Fireworks做好的图片,不过好象只能做空白图 :( mxp/这个插件用来代替...
文章目录JavaScript的逻辑内存模型一、面向对象的三要素二、JavaScript的逻辑内存模型三、JavaScript的对象与Java的实例四、window对象的内存逻辑模型五、Object构造函数的内存逻辑模型六、Function构造函数的内存...
利用asp.net轻松实现js里面的alert,windows弹窗,返回上级history.go,已经关闭窗体 window.close();等功能,不用每次要在事件下写繁杂的Response.Write("<script>alert('你不具备该模块管理权限,请联系管理员!')...
-一个典型应用,在Window控件中打开新页面,如果传递的参数不正确,则首先提示参数不对然后关闭此弹出窗口。 -ExtAspNet.Alert.Show("参数错误!", String.Empty, ExtAspNet.ActiveWindow.GetCloseReference());...
-修正了IE下Grid中的一个JS问题(feedback:lqm4108)。 -修正Alert消息中引号未编码导致的JS错误(feedback:sun1299shine)。 +集成extjs3.0.3。 -修正弹出对话框的宽度计算错误(会保持最小的状态)。 -增加新的...
1. 较上一版本,增加一个frameset模块,是基于 iejoyswebos桌面的程序框架模块,可以用它来做桌面程序集合应用,它也是动态加载所集合模块JS包和CSS包,并且与桌面加载不冲突,它所加载的功能是以tabpanel的模式...
封装一个数组类 2 函数使用时注意事项 2 with语句 4 for,in 4 DOM 5 window 6 table 9 input 16 select 17 form 19 Ajax 22 接收文本数据 22 接收xml数据 23 接收json数据 24 多级菜单 25 用json...
软件介绍 qWikiOffice(以下简称Qo)是一个开源的仿Window Vista的Web桌面系统,Qo的桌面图形界面基于Ext Js的Ajax框架。Qo不仅外观友好且为开发人员开发插件提供了强大的平台,您可以在Qo里很快的开发属于自己的应用...
于是就有了下面这个简单的DialogHelper辅助类,因为这篇文章分享的重点是思路,所以目前版本的代码也还非常粗糙。思路对了,后续再封装成什么样都不过是形式而已,希望这个思路能给大家点启迪,同时欢迎大家开拓思维...
模块化是一个语言膨胀的必经之路,它能够帮助开发者拆分和组织代码。 Module模式 在模块化规范形成之前,JS开发者使用Module设计模式来解决JS全局作用域的污染问题。Module模式最初被定义为一种在传统软件工程中为...
jQuery就是一个函数,你也可以把它当成类(呵呵,本身就是类)。 代码如下: (function(){ var jQuery = function() { // 函数体 } window.jQuery = window.$ = jQuery; })(); console.log(jQuery); 上面的空函数...