shade.0.2.js
资源名称:cindyblog.rar [点击查看]
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:4k
源码类别:
Jsp/Servlet
开发平台:
Java
- //得到浏览器显示的屏幕高度
- document.getViewportHeight = function(){
- if (window.innerHeight!=window.undefined) return window.innerHeight;
- if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
- if (document.body) return document.body.clientHeight;
- return window.undefined;
- }
- //得到浏览器显示的屏幕宽度
- document.getViewportWidth = function(){
- if (window.innerWidth!=window.undefined) return window.innerWidth;
- if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
- if (document.body) return document.body.clientWidth;
- }
- /**
- * 遮罩层,组件的显示及隐藏
- */
- Shade = {
- mask:null,
- container:null,
- isIE6:null,
- init:function(){
- //判断浏览器是否是ie6或其以下版本
- var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
- if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
- this.isIE6 = true;
- }else{
- this.isIE6 = false;
- }
- //将遮罩层加入body
- var popmask = document.createElement('div');
- popmask.id = 'mask';
- document.body.appendChild(popmask);
- this.mask = document.getElementById("mask");
- //将组件边框加入body
- var popcont = document.createElement('div');
- popcont.id = 'popupContainer';
- popcont.innerHTML ="<div id='popupInner'>"+
- "<div id='popupTitleBar'>"+
- "<div id='popupTitle'></div>"+
- "<div id='popupControls'>"+
- "<img src='images/close.gif' onclick='Shade.hide();' id='popCloseBox' />"+
- "</div></div>"+
- "<div id='popupFrame'>dd</div>";
- document.body.appendChild(popcont);
- this.container = document.getElementById("popupContainer");
- },
- setMaskSize:function(){
- var theBody = document.body;
- var fullHeight = document.getViewportHeight();
- var fullWidth = document.getViewportWidth();
- // Determine what's bigger, scrollHeight or fullHeight / width
- if (fullHeight > theBody.scrollHeight) {
- this.popHeight = fullHeight;
- } else {
- this.popHeight = theBody.scrollHeight;
- }
- if (fullWidth > theBody.scrollWidth) {
- this.popWidth = fullWidth;
- } else {
- this.popWidth = theBody.scrollWidth;
- }
- this.mask.style.height = this.popHeight + "px";
- this.mask.style.width = this.popWidth + "px";
- },
- toCenter:function(conf){
- var s = this.container.style;
- s.left = (document.getViewportWidth()-conf.width)/2+"px";
- s.top = (document.getViewportHeight()-conf.height)/2+"px";
- },
- show:function(conf){
- //初始化
- this.init();
- //设置遮罩层的长度和宽度
- this.setMaskSize()
- //设置组件的标题
- document.getElementById('popupTitle').innerHTML = conf.title;
- //设置组件的长和宽
- this.container.style.width = conf.width+"px";
- this.container.style.height = conf.height+"px";
- var frame = document.getElementById('popupFrame');
- frame.style.width = (conf.width -4)+"px";
- frame.style.height = (conf.height -31)+"px";
- //将组件居中显示
- this.toCenter(conf);
- //设置组件内容
- frame.innerHTML = conf.templete;
- this.render(conf);
- this.enDrag();
- var Shade_this = this ; //传递this参数,到浏览器窗体改变事件
- Shade_this.conf = conf ;
- window.onresize = function(){
- if (Shade_this.container) {
- Shade_this.render(Shade_this.conf);
- }
- } ;
- },
- hide:function(){
- //删除遮罩层
- document.body.removeChild(this.mask);
- //删除组件层
- document.body.removeChild(this.container);
- },
- /*增加拖动功能*/
- enDrag: function(){
- var popupTitleBar = document.getElementById('popupTitleBar') ;
- popupTitleBar.style.cursor = "move" ;
- Drag.init(popupTitleBar,this.container);
- } ,
- render: function(conf){
- this.setMaskSize();
- this.toCenter(conf);
- }
- }