jQuery实现简单网页遮罩层/弹出层效果兼容IE6、IE7 - Web前端
作者:98wpeu发布时间:2026-08-01分类:网页前端技术浏览:1
导读:本屌丝最近工作要求重写网站所有代码,so...极其蛋疼的事情出现了,管我的人要求不能用网上的插件,oh~~~mygod!!这是多么能让千万只草原上的马儿奔腾的要求~~~先实现...
本屌丝最近工作要求重写网站所有代码,so...极其蛋疼的事情出现了,管我的人要求不能用网上的插件,oh~~~my god!! 这是多么能让千万只草原上的马儿奔腾的要求~~~
先实现一个比较简单的功能:
需求:网页遮罩层/弹出层,兼容IE6
幸好本屌丝以前聪明收集了个JS的版本,so,自己改写成了jQuery插件形式的,方便以后使用。
屁话不多放,无码无真相!
复制代码 代码如下:
/*******************************
* @name Layer跨浏览器兼容插件 v1.0
*******************************/
;(function($){
$.fn.layer = function(){
var isie = (document.all) ? true : false;
var isIE6 = isIE && !window.XMLHttpRequest;
var position = !isIE6 ? "fixed" : "absolute";
var contAInerBox = JQuery(this);
containerBox.CSS({"z-index":"9999","display":"block","position":position ,"top":"50%","left":"50%","margin-top": -(containerBox.height()/2)+ "px","margin-left": -(containerBox.width()/2) + "px"});
var layer=jQuery("<div></div>");
layer.css({"width":"100%","height":"100%","position":position,"top":"0px","left":"0px","background-color":"#000","z-index":"9998","opacity":"0.6"});
jquery("body").append(layer);
function layer_iestyle(){
var maxWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
var maxHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
layer.css({"width" : maxWidth , "height" : maxHeight });
}
function containerBox_iestyle(){
var margintop = jquery(document).scrollTop - containerBox.height()/ 2 + "px";
var marginLeft = JQuery(document).scrollLeft - containerBox.width()/ 2 + "px";
containerBox.css({"margin-top" : marginTop , "margin-left" : marginLeft });
}
if(isIE){
layer.css("filter","alpha(opacity=60)");
}
if(isIE6){
layer_iestyle();
containerBox_iestyle();
}
jQuery("window").resize(function(){
layer_iestyle();
});
layer.click(function(){
containerBox.hide();
jQuery(this).remove();
});
};
})(jQuery);
哈哈,是不是很简单,但是此处有个比较大的bug,没法让IE6支持背景色透明,所以,在IE6的显示下,就会出现一大片屎黑色~~~~
现在来说说使用方法:
第一步:引用jquery文件,这个不多说,自己下去吧,http://jquery.com
第二步:把我这个插件引用进去,这个也不多说,点击下载,
第三步:你看,你要显示在中间的内容box,我是不是没法给你实现,所以,需要你自己建一个,放在网页最下端即可,
eg:
复制代码 代码如下:
<div id="kabulore-layer">
<div class="box_container">
弹弹弹,弹走鱼尾纹~~
</div>
</div>
第四步:在你要弹出来这个内容框的地方加个时间,以click为例:
复制代码 代码如下:
$("#tan").click(function(){
$("#kabulore-layer").layer();
});
大功告成!
注:此插件是点击灰色区域的时候,该弹出层自动隐藏,如果想加个关闭按钮再隐藏,可自己写一下close事件
先实现一个比较简单的功能:
需求:网页遮罩层/弹出层,兼容IE6
幸好本屌丝以前聪明收集了个JS的版本,so,自己改写成了jQuery插件形式的,方便以后使用。
屁话不多放,无码无真相!
复制代码 代码如下:
/*******************************
* @name Layer跨浏览器兼容插件 v1.0
*******************************/
;(function($){
$.fn.layer = function(){
var isie = (document.all) ? true : false;
var isIE6 = isIE && !window.XMLHttpRequest;
var position = !isIE6 ? "fixed" : "absolute";
var contAInerBox = JQuery(this);
containerBox.CSS({"z-index":"9999","display":"block","position":position ,"top":"50%","left":"50%","margin-top": -(containerBox.height()/2)+ "px","margin-left": -(containerBox.width()/2) + "px"});
var layer=jQuery("<div></div>");
layer.css({"width":"100%","height":"100%","position":position,"top":"0px","left":"0px","background-color":"#000","z-index":"9998","opacity":"0.6"});
jquery("body").append(layer);
function layer_iestyle(){
var maxWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
var maxHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
layer.css({"width" : maxWidth , "height" : maxHeight });
}
function containerBox_iestyle(){
var margintop = jquery(document).scrollTop - containerBox.height()/ 2 + "px";
var marginLeft = JQuery(document).scrollLeft - containerBox.width()/ 2 + "px";
containerBox.css({"margin-top" : marginTop , "margin-left" : marginLeft });
}
if(isIE){
layer.css("filter","alpha(opacity=60)");
}
if(isIE6){
layer_iestyle();
containerBox_iestyle();
}
jQuery("window").resize(function(){
layer_iestyle();
});
layer.click(function(){
containerBox.hide();
jQuery(this).remove();
});
};
})(jQuery);
哈哈,是不是很简单,但是此处有个比较大的bug,没法让IE6支持背景色透明,所以,在IE6的显示下,就会出现一大片屎黑色~~~~
现在来说说使用方法:
第一步:引用jquery文件,这个不多说,自己下去吧,http://jquery.com
第二步:把我这个插件引用进去,这个也不多说,点击下载,
第三步:你看,你要显示在中间的内容box,我是不是没法给你实现,所以,需要你自己建一个,放在网页最下端即可,
eg:
复制代码 代码如下:
<div id="kabulore-layer">
<div class="box_container">
弹弹弹,弹走鱼尾纹~~
</div>
</div>
第四步:在你要弹出来这个内容框的地方加个时间,以click为例:
复制代码 代码如下:
$("#tan").click(function(){
$("#kabulore-layer").layer();
});
大功告成!
注:此插件是点击灰色区域的时候,该弹出层自动隐藏,如果想加个关闭按钮再隐藏,可自己写一下close事件
相关推荐
- jQuery实现购物车多物品数量的加减+总价计算 - Web前端
- jquery修改网页背景颜色通过css方法实现 - Web前端
- jquery实现保存已选用户 - Web前端
- jQuery filter函数使用方法 - Web前端
- jquery中常用的函数和属性详细解析 - Web前端
- jQuery is()函数用法3例 - Web前端
- jquery form 隐藏的input 选择 - Web前端
- jquery插件冲突(jquery.noconflict)解决方法分享 - Web前端
- Jquery实现自定义窗口随意的拖拽 - Web前端
- jQuery调用RESTful WCF示例代码(GET方法/POST方法) - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3【第六章】Foundation之按钮和下拉功能 - Web前端
- 4jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 9在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


