六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 146|回复: 0

JS遮盖层解决方案

[复制链接]

升级  48%

34

主题

34

主题

34

主题

秀才

Rank: 2

积分
122
 楼主| 发表于 2013-2-8 00:22:02 | 显示全部楼层 |阅读模式
 
页面中的HTML
<div id="bg" class="bg"> </div> 
 CSS代码
.bg {display:none;background-color: #666;filter:alpha(opacity=50);/*IE*/opacity:0.5;/*FF*/z-index:10;position:absolute;} 
JS代码
function getPageSizeWithScroll(){if (window.innerHeight && window.scrollMaxY) {// FirefoxyWithScroll = window.innerHeight + window.scrollMaxY;xWithScroll = window.innerWidth + window.scrollMaxX;} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer MacyWithScroll = document.body.scrollHeight;xWithScroll = document.body.scrollWidth;} else { // works in Explorer 6 Strict, Mozilla (not FF) and SafariyWithScroll = document.body.offsetHeight;xWithScroll = document.body.offsetWidth;  }return [xWithScroll, yWithScroll];}function SuperMan(){var de = document.documentElement;return {show_bg: function(){var size = getPageSizeWithScroll();$("#bg").css({left:0, top:0, width:'100%', height:size[1]}).show();},hide_bg: function(){$("#bg").hide();}}} 
JS代码
function SuperMan(){var _select_cache;return {show_bg: function(hide_select){var size = getPageSizeWithScroll();$("#bg").css({left:0, top:0, width:'100%', height:size[1]}).show();if(hide_select){_select_cache = $('select:visible');_select_cache.css('visibility', 'hidden');}},hide_bg: function(){$("#bg").hide();if( _select_cache ){_select_cache.css('visibility', 'visible');_select_cache = false;}}}}window.superman = SuperMan(); 
调用示例:
superman.show_bg();superman.hide_bg(); 
over
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表