自写jQuery插件,实现简单网页遮罩层/弹出层功能,兼容IE6、IE7

本屌丝最近工作要求重写网站所有代码,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

第二步:把我这个插件引用进去,这个也不多说,自己下去吧,http://download.csdn.net/download/u010480479/7305857

第三步:你看,你要显示在中间的内容box,我是不是没法给你实现,所以,需要你自己建一个,放在网页最下端即可,

eg:

<div id="kabulore-layer">
	<div class="box_container">
		弹弹弹,弹走鱼尾纹~~
	</div>
</div>

第四步:在你要弹出来这个内容框的地方加个时间,以click为例:

$("#tan").click(function(){
	$("#kabulore-layer").layer();
});


 大功告成! 


注:此插件是点击灰色区域的时候,该弹出层自动隐藏,如果想加个关闭按钮再隐藏,可自己写一下close事件


如有任何交流或者指教,请联系:http://www.yinmu.me


后续完善版会逐渐跟上,目前在赶项目,比较苦逼的忙~~



说明 这个控件实现相当简单,基于jQuery实现,只编写一些基本功能,满足一般使用。提供原代码,可以根据自己的项目要求修改,只在IE6IE7、IE8、IE9中测试。有问题联系邮箱:zliuyao2010@163.com 初始化构造 构造方法在:input表单添加class="e_select"属性 属性说明:class="e_select" 构造下拉 属性说明:etop="0" 控件下图片位置,默认可以不用添加此属性。 属性说明:edata="{,普通:普通AA,模糊:模糊,右边模糊:右边模糊}" or {"":"","男":"男1","女":"女1","其他":"其他1"} 下拉控件中的值,注意:支持两种赋值,json格式以及键值对形式,PS:若下拉列表中有空值键对用英文的“,”,json格式用:"":""。 属性说明:echange="echange" 选择下拉值的回调方法名称,PS:只要输入方法名称,调用方法中有两个参数key(键) 和 value(值) 例如:function echange(key,value) {alert(key + " " + value);} 动态赋值 function setValue() { jQuery("#text1").val("").attr("data","");//赋值请清空原来的值(很重要) jQuery("#text1").attr("edata",'{"":"","男":"男1","女":"女1","其他":"其他1"}'); } 获取值 function getValue() { alert("key:"+document.getElementById("text1").value + " value:" + document.getElementById("text1").data); } 事件 function echange(key,value) { alert("key:"+key + " " + "value:"+value); } 测试 省: 市: 区: 普通模糊右边模糊普通模糊右边模糊普通模糊右边模糊
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值