jQuery實(shí)現(xiàn)簡(jiǎn)單網(wǎng)頁(yè)遮罩層/彈出層效果兼容IE6、IE7
更新時(shí)間:2014年06月16日 16:42:42 投稿:whsnow
自寫寫的一個(gè)jQuery插件,可以實(shí)現(xiàn)簡(jiǎn)單網(wǎng)頁(yè)遮罩層/彈出層功能,并且兼容IE6、IE7,需要的朋友可以參考下
本屌絲最近工作要求重寫網(wǎng)站所有代碼,so...極其蛋疼的事情出現(xiàn)了,管我的人要求不能用網(wǎng)上的插件,oh~~~my god!! 這是多么能讓千萬只草原上的馬兒奔騰的要求~~~
先實(shí)現(xiàn)一個(gè)比較簡(jiǎn)單的功能:
需求:網(wǎng)頁(yè)遮罩層/彈出層,兼容IE6
幸好本屌絲以前聰明收集了個(gè)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);
哈哈,是不是很簡(jiǎn)單,但是此處有個(gè)比較大的bug,沒法讓IE6支持背景色透明,所以,在IE6的顯示下,就會(huì)出現(xiàn)一大片屎黑色~~~~
現(xiàn)在來說說使用方法:
第一步:引用jquery文件,這個(gè)不多說,自己下去吧,http://jquery.com
第二步:把我這個(gè)插件引用進(jìn)去,這個(gè)也不多說,點(diǎn)擊下載,
第三步:你看,你要顯示在中間的內(nèi)容box,我是不是沒法給你實(shí)現(xiàn),所以,需要你自己建一個(gè),放在網(wǎng)頁(yè)最下端即可,
eg:
<div id="kabulore-layer">
<div class="box_container">
彈彈彈,彈走魚尾紋~~
</div>
</div>
第四步:在你要彈出來這個(gè)內(nèi)容框的地方加個(gè)時(shí)間,以click為例:
$("#tan").click(function(){
$("#kabulore-layer").layer();
});
大功告成!
注:此插件是點(diǎn)擊灰色區(qū)域的時(shí)候,該彈出層自動(dòng)隱藏,如果想加個(gè)關(guān)閉按鈕再隱藏,可自己寫一下close事件
先實(shí)現(xiàn)一個(gè)比較簡(jiǎn)單的功能:
需求:網(wǎng)頁(yè)遮罩層/彈出層,兼容IE6
幸好本屌絲以前聰明收集了個(gè)js的版本,so,自己改寫成了jQuery插件形式的,方便以后使用。
屁話不多放,無碼無真相!
復(fù)制代碼 代碼如下:
/*******************************
* @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);
哈哈,是不是很簡(jiǎn)單,但是此處有個(gè)比較大的bug,沒法讓IE6支持背景色透明,所以,在IE6的顯示下,就會(huì)出現(xiàn)一大片屎黑色~~~~
現(xiàn)在來說說使用方法:
第一步:引用jquery文件,這個(gè)不多說,自己下去吧,http://jquery.com
第二步:把我這個(gè)插件引用進(jìn)去,這個(gè)也不多說,點(diǎn)擊下載,
第三步:你看,你要顯示在中間的內(nèi)容box,我是不是沒法給你實(shí)現(xiàn),所以,需要你自己建一個(gè),放在網(wǎng)頁(yè)最下端即可,
eg:
復(fù)制代碼 代碼如下:
<div id="kabulore-layer">
<div class="box_container">
彈彈彈,彈走魚尾紋~~
</div>
</div>
第四步:在你要彈出來這個(gè)內(nèi)容框的地方加個(gè)時(shí)間,以click為例:
復(fù)制代碼 代碼如下:
$("#tan").click(function(){
$("#kabulore-layer").layer();
});
大功告成!
注:此插件是點(diǎn)擊灰色區(qū)域的時(shí)候,該彈出層自動(dòng)隱藏,如果想加個(gè)關(guān)閉按鈕再隱藏,可自己寫一下close事件
您可能感興趣的文章:
- JS遮罩層效果 兼容ie firefox jQuery遮罩層
- JQuery 遮罩層實(shí)現(xiàn)(mask)實(shí)現(xiàn)代碼
- jQuery操作dom實(shí)現(xiàn)彈出頁(yè)面遮罩層(web端和移動(dòng)端阻止遮罩層的滑動(dòng))
- jQuery阻止移動(dòng)端遮罩層后頁(yè)面滾動(dòng)
- Jquery實(shí)現(xiàn)遮罩層的簡(jiǎn)單實(shí)例(就是彈出DIV周圍都灰色不能操作)
- jQuery+AJAX實(shí)現(xiàn)遮罩層登錄驗(yàn)證界面(附源碼)
- jQuery點(diǎn)擊按鈕彈出遮罩層且內(nèi)容居中特效
- Jquery實(shí)現(xiàn)遮罩層的方法
- jQuery實(shí)現(xiàn)彈出帶遮罩層的居中浮動(dòng)窗口效果
- jQuery實(shí)現(xiàn)打開網(wǎng)頁(yè)自動(dòng)彈出遮罩層或點(diǎn)擊彈出遮罩層功能示例
- JavaScript實(shí)現(xiàn)的彈出遮罩層特效經(jīng)典示例【基于jQuery】
相關(guān)文章
jQuery三組基本動(dòng)畫與自定義動(dòng)畫操作實(shí)例總結(jié)
這篇文章主要介紹了jQuery三組基本動(dòng)畫與自定義動(dòng)畫操作,結(jié)合實(shí)例形式總結(jié)了jQuery基本動(dòng)畫函數(shù)與自定義動(dòng)畫相關(guān)操作技巧及使用注意事項(xiàng),需要的朋友可以參考下2020-05-05jQuery實(shí)現(xiàn)彈出窗口中切換登錄與注冊(cè)表單
本文給大家推薦的是一款jQuery實(shí)現(xiàn)彈出窗口中切換登錄與注冊(cè)表單的特效。適用瀏覽器:IE8+、FireFox、Chrome、Safari、Opera。十分的方便實(shí)用,有需要的小伙伴可以參考下。2015-06-06jquery+springboot實(shí)現(xiàn)文件上傳功能
這篇文章主要為大家詳細(xì)介紹了jquery+springboot文件上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11簡(jiǎn)單實(shí)現(xiàn)的JQuery文本框水印插件
這篇文章主要為大家詳細(xì)介紹了簡(jiǎn)單實(shí)現(xiàn)JQuery文本框水印插件的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06