jQuery實現(xiàn)簡單網(wǎng)頁遮罩層/彈出層效果兼容IE6、IE7
更新時間:2014年06月16日 16:42:42 投稿:whsnow
自寫寫的一個jQuery插件,可以實現(xiàn)簡單網(wǎng)頁遮罩層/彈出層功能,并且兼容IE6、IE7,需要的朋友可以參考下
本屌絲最近工作要求重寫網(wǎng)站所有代碼,so...極其蛋疼的事情出現(xiàn)了,管我的人要求不能用網(wǎng)上的插件,oh~~~my god!! 這是多么能讓千萬只草原上的馬兒奔騰的要求~~~
先實現(xiàn)一個比較簡單的功能:
需求:網(wǎng)頁遮罩層/彈出層,兼容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的顯示下,就會出現(xiàn)一大片屎黑色~~~~
現(xiàn)在來說說使用方法:
第一步:引用jquery文件,這個不多說,自己下去吧,http://jquery.com
第二步:把我這個插件引用進去,這個也不多說,點擊下載,
第三步:你看,你要顯示在中間的內(nèi)容box,我是不是沒法給你實現(xiàn),所以,需要你自己建一個,放在網(wǎng)頁最下端即可,
eg:
<div id="kabulore-layer">
<div class="box_container">
彈彈彈,彈走魚尾紋~~
</div>
</div>
第四步:在你要彈出來這個內(nèi)容框的地方加個時間,以click為例:
$("#tan").click(function(){
$("#kabulore-layer").layer();
});
大功告成!
注:此插件是點擊灰色區(qū)域的時候,該彈出層自動隱藏,如果想加個關閉按鈕再隱藏,可自己寫一下close事件
先實現(xiàn)一個比較簡單的功能:
需求:網(wǎng)頁遮罩層/彈出層,兼容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的顯示下,就會出現(xiàn)一大片屎黑色~~~~
現(xiàn)在來說說使用方法:
第一步:引用jquery文件,這個不多說,自己下去吧,http://jquery.com
第二步:把我這個插件引用進去,這個也不多說,點擊下載,
第三步:你看,你要顯示在中間的內(nèi)容box,我是不是沒法給你實現(xiàn),所以,需要你自己建一個,放在網(wǎng)頁最下端即可,
eg:
復制代碼 代碼如下:
<div id="kabulore-layer">
<div class="box_container">
彈彈彈,彈走魚尾紋~~
</div>
</div>
第四步:在你要彈出來這個內(nèi)容框的地方加個時間,以click為例:
復制代碼 代碼如下:
$("#tan").click(function(){
$("#kabulore-layer").layer();
});
大功告成!
注:此插件是點擊灰色區(qū)域的時候,該彈出層自動隱藏,如果想加個關閉按鈕再隱藏,可自己寫一下close事件
您可能感興趣的文章:
- JS遮罩層效果 兼容ie firefox jQuery遮罩層
- JQuery 遮罩層實現(xiàn)(mask)實現(xiàn)代碼
- jQuery操作dom實現(xiàn)彈出頁面遮罩層(web端和移動端阻止遮罩層的滑動)
- jQuery阻止移動端遮罩層后頁面滾動
- Jquery實現(xiàn)遮罩層的簡單實例(就是彈出DIV周圍都灰色不能操作)
- jQuery+AJAX實現(xiàn)遮罩層登錄驗證界面(附源碼)
- jQuery點擊按鈕彈出遮罩層且內(nèi)容居中特效
- Jquery實現(xiàn)遮罩層的方法
- jQuery實現(xiàn)彈出帶遮罩層的居中浮動窗口效果
- jQuery實現(xiàn)打開網(wǎng)頁自動彈出遮罩層或點擊彈出遮罩層功能示例
- JavaScript實現(xiàn)的彈出遮罩層特效經(jīng)典示例【基于jQuery】
相關文章
jquery+springboot實現(xiàn)文件上傳功能
這篇文章主要為大家詳細介紹了jquery+springboot文件上傳,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11