本屌絲最近工作要求重寫網(wǎng)站所有代碼,so...極其蛋疼的事情出現(xiàn)了,管我的人要求不能用網(wǎng)上的插件,oh~~~my god!! 這是多么能讓千萬只草原上的馬兒奔騰的要求~~~ 
先實現(xiàn)一個比較簡單的功能: 
需求:網(wǎng)頁遮罩層/彈出層,兼容IE6 
幸好本屌絲以前聰明收集了個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); 
復(fù)制代碼 代碼如下:
 
<div> 
<div> 
彈彈彈,彈走魚尾紋~~ 
</div> 
</div> 
復(fù)制代碼 代碼如下:
 
$("#tan").click(function(){ 
$("#kabulore-layer").layer(); 
}); 
新聞熱點
疑難解答
圖片精選