jquery 鎖定彈出層實(shí)現(xiàn)代碼
這個(gè)東西也是隨手總結(jié)出來(lái)的,引用了一些js框架jquery的方法。
div遮蓋其他控件的方法參考了 對(duì)于需要遮蓋flash的,請(qǐng)將flash控件的WMode變量值設(shè)置為T(mén)ransparent
使用方法:
<script src="jquery.js"></script>
<script src="effect/maskDiv.js"></script>
<script>
//配置模塊
var moduleEvent = [{"idName":"close" , "eventName":"click" , "doMethod":"CLOSE_DIV"},{"idObj":window,"eventName":"resize" , "doMethod":"RESIZE_WINDOW"}];
qihoo_effect_maskDiv.showMaskDiv("your div id" , moduleEvent); //請(qǐng)把div的display設(shè)置為none。
*******************************************************
effect/maskDiv.js
var qihoo_effect_maskDiv = {
_module : {},
_css : {},
_instance : "" ,
_event : {"CLOSE_WINDOW" : function() { window.close(); } , "CLOSE_DIV" : function(){qihoo_effect_maskDiv.closeDiv();} , "RESIZE_WINDOW" : function(){qihoo_effect_maskDiv.resizeWindow();} },
_isIe : eval("false;/*@cc_on@if(@\x5fwin32)isMSIE=true@end@*/") ,
init : function (){
if (this._instance){
return this._instance;
}
this.appendBackGroundDiv();
this._instance = this;
return this._instance;
},
appendBackGroundDiv : function (){
this._module.backGroundDiv = $("<div id='qihoo_effect_maskDiv_module_backGroundDiv'></div>");
this._module.backGroundDiv.appendTo("body");
this._css.mask = { "background-color":"#000" , "position":"absolute", "-moz-opacity": "0.75" , "filter":"alpha(opacity=75)","z-index":5 , "width" : document.body.clientWidth+100 , "height" : document.body.clientHeight+300 , "top" : "0px" , "left":"0px" , "display" : "none"};
this._module.backGroundDiv.css(this._css.mask);
this._module.coverIframe = $("<iframe src='javascript:false' id='qihoo_effect_maskDiv_module_iframe' frameborder='1'></iframe>");
this._css.normalIframe = {'position':'absolute','left':'-1000px','top':'-1000px','z-index':7};
this._module.coverIframe.css(this._css.normalIframe);
this._module.coverIframe.appendTo("body");
},
showMaskDiv : function (showDivId , moduleEvent, position ){
instance = this;
if (this._isIe){
if(document.readyState != "complete"){
setTimeout(function(){instance.showMaskDiv(showDivId , moduleEvent , position);} , 100);
return false;
}
}
if ("" == this._instance){
this.init();
}
this._module.showDiv = $("#"+showDivId);
if (typeof position == 'undefined'){
this._css.coverIframe = {'position':'absolute','top':parseInt(screen.height/4+document.documentElement.scrollTop)+"px",'left':parseInt(screen.width/4+document.documentElement.scrollLeft)+"px",'zIndex':7};
this._css.coverd = {"zIndex" : 10 , "position" : "absolute" ,"width":"400px" , "height":"240px" ,"top": parseInt(screen.height/4+document.documentElement.scrollTop)+"px", "left":parseInt(screen.width/4+document.documentElement.scrollLeft)+"px"};
}
else{
this._css.coverIframe = {'position':'absolute',"height" : position.height, "width":position.width , "top": position.top , "left":position.left,'zIndex':7};
this._css.coverd = {"zIndex" : 10 , "position" : "absolute" , "height" : position.height, "width":position.width , "top": position.top , "left":position.left};
}
for (var i in moduleEvent){
if (typeof moduleEvent[i].idName != "undefined") {
$("#"+moduleEvent[i].idName).bind(moduleEvent[i].eventName , this._event[moduleEvent[i].doMethod]);
}
if (typeof moduleEvent[i].idObj != "undefined") {
$(moduleEvent[i].idObj).bind(moduleEvent[i].eventName , this._event[moduleEvent[i].doMethod]);
}
}
this._module.backGroundDiv.show();
showDivFront = this._module.showDiv;
cssParam = this._css;
coveredIframe = this._module.coverIframe;
this._module.backGroundDiv.animate({opacity:0.75},"normal" , function(){coveredIframe.css(cssParam.coverIframe);showDivFront.show();});
this._module.showDiv.css(this._css.coverd);
},
resizeWindow : function (){
this._css.mask = { "background-color":"#000" , "position":"absolute", "-moz-opacity": "0.75" , "opacity":"0.75" , "filter":"alpha(opacity=75)","zIndex":5 , "width" : document.body.clientWidth+100, "height" : document.body.clientHeight+300 , "top" : "0px" , "left":"0px"};
this._module.backGroundDiv.css(this._css.mask);
},
closeDiv : function (){
this._module.coverIframe.css(this._css.normalIframe);
this._module.showDiv.hide();
hidebBackGroundDiv = this._module.backGroundDiv;
this._module.backGroundDiv.animate({opacity:0},"normal", function(){hidebBackGroundDiv.hide();});
}
};
看評(píng)論所言,加了一點(diǎn)用法:
這里是一個(gè)不引入jquery框架的實(shí)現(xiàn)同樣效果的程序。
引入文件
<script src="/js/jquery.js"></script>
<script src="/js/maskDiv.js"></script>
配置事件
<script>
var moduleEvent = [
{"idName":"closeForm" , "eventName":"click" , "doMethod":"CLOSE_DIV"},
{"idObj":window,"eventName":"resize" , "doMethod":"RESIZE_WINDOW"}
];
</script>
注:idName是綁定事件的html組件的id,idObj是html控件變量
配置初始位置(可選步驟)
<script>
var position = {"width":"300px", "height":"400px" , "top":"300px", "left":"720px"};
</script> 顯示遮罩層
qihoo_effect_maskDiv.showMaskDiv(divId, moduleEvent , position);或者qihoo_effect_maskDiv.showMaskDiv(divId, moduleEvent );
隱去遮罩層
qihoo_effect_maskDiv.closeDiv();
js實(shí)現(xiàn)的遮蓋層的定義:
經(jīng)常遇到要彈出一個(gè)懸浮層,鼠標(biāo)的事件只能在本層上有效,底層會(huì)失效。能用的做 法是在懸浮層和底層之間在加一個(gè)遮蓋層,遮蓋住整個(gè)瀏覽器,這樣就不能點(diǎn)擊底層的任何東西了。
var w = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px"; //獲取寬
var h = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px"; //獲取高
//定義一個(gè)透明背景層
var gb = $("<div/>").attr("id","gb")
.css({top:"0",left:"0",zIndex:"2",position:"absolute",filter:"alpha(opacity=0)",background:"#fff"})
.css("width",w).css("height",h)
其實(shí)說(shuō)明最主要還是說(shuō)明一下背景層的CSS定義。首先要使top和left有效,就要設(shè)置 position:absolute。filter:"alpha(opacity=0)設(shè)置透明度,數(shù)值0-100,0表示完全透明,100表示不透明。background設(shè)置背景層的顏色。zIndex的值只要比底層的高,比彈出層的低就行了。(zIndex的值越大表示越在上層)。好了,基本就是這樣吧!
相關(guān)文章
jQuery實(shí)現(xiàn)分頁(yè)功能(含ajax請(qǐng)求、后臺(tái)數(shù)據(jù)、附完整demo)
這篇文章主要給大家介紹了關(guān)于jQuery實(shí)現(xiàn)分頁(yè)功能的相關(guān)資料,主要包含ajax請(qǐng)求和后臺(tái)數(shù)據(jù),文末給出了完整的demo示例,對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-04-04jquery樹(shù)形菜單效果的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇jquery樹(shù)形菜單效果的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06jQuery實(shí)現(xiàn)浮動(dòng)層隨瀏覽器滾動(dòng)條滾動(dòng)的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)浮動(dòng)層隨瀏覽器滾動(dòng)條滾動(dòng)的方法,涉及jQuery操作頁(yè)面元素滾動(dòng)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09jQuery 源碼分析筆記(3) Deferred機(jī)制
從1.5版本開(kāi)始,jQuery加入了Deferred功能,讓事件處理隊(duì)列更加的完善。并用這個(gè)機(jī)制重寫(xiě)了Ajax模塊。雖然還沒(méi)輪到Ajax,但是接下來(lái)的事件處理函數(shù)中牽扯到了這個(gè)機(jī)制,所以提前看這段代碼。2011-06-06Bootstrap table中toolbar新增條件查詢(xún)及refresh參數(shù)使用方法
這篇文章主要介紹了Bootstrap table中toolbar新增條件查詢(xún)及refresh參數(shù)使用方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-05-05基于jquery實(shí)現(xiàn)的服務(wù)器驗(yàn)證控件的啟用和禁用代碼
用戶(hù)點(diǎn)擊下一步時(shí),不對(duì)Display=none的新增區(qū)域表單進(jìn)行驗(yàn)證,需要在用戶(hù)點(diǎn)擊“取消增加時(shí)”,禁用服務(wù)器驗(yàn)證控件。反之,啟用服務(wù)器驗(yàn)證控件。2010-04-04jquery 利用show和hidden實(shí)現(xiàn)級(jí)聯(lián)菜單示例代碼
級(jí)聯(lián)菜單的實(shí)現(xiàn)方法有很多,在本文為大家介紹下使用show和hidden輕松實(shí)現(xiàn)下級(jí)聯(lián)效果,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08JQuery調(diào)用WebServices的方法和4個(gè)實(shí)例
你是不是經(jīng)常作這種開(kāi)發(fā),前端用JS寫(xiě)邏輯,后端用aspx或者ashx作服務(wù)?你是不是經(jīng)常在請(qǐng)求aspx的時(shí)候在查詢(xún)字符串中拼接諸如a.aspx?method=getDepartmetn¶m1=1¶m2=2的字符串?2014-05-05