js彈出層(jQuery插件形式附帶reLoad功能)
(function($){
$.module={
_showCoverLayer:function(){//顯示遮蓋層
this.coverLayer=$("#TB_overlay");
var height=$(document).height()+"px";
var width=$(document).width()+"px";
if(this.coverLayer.length>0){
this.coverLayer.css({"visibility":"visible","height":height,"width":width});
}else{
this.coverLayer=$("<div id='TB_overlay' style='height:"+height+";width:"+width+"'></div>");
$("body").append(this.coverLayer);
}
},
_hideCoverLayer:function(){//隱藏遮蓋層
this.coverLayer.css("visibility","hidden");
},
_showAjaxLoad:function(imgUrl){
this.ajaxLayer=$("#TB_load");
if(this.ajaxLayer.length>0){
this.ajaxLayer.css({"visibility":"visible"});
$("#TB_loadContent").css({"display":"block"});
}else{
this.ajaxLayer=$("<div id='TB_load'><div id='TB_loadContent'><img src='"+imgUrl+"' /></div></div>");
$("body").append(this.ajaxLayer);
}
},
_hideAjaxLoad:function(){
this.ajaxLayer.css("visibility","hidden");
$("#TB_loadContent").css({"display":"none"});
},
showWin:function(opt){//url,title,width,height,fixTop,fixLeft,imgUrl,top
this._showCoverLayer();
this.imgUrl=opt.imgUrl || "/image/ajax-loader.gif";
this._showAjaxLoad(this.imgUrl);
this.win=$("#TB_window");
var that=this;
if(this.win.length==0){
this.win=$("<div id='TB_window'></div>");
$("body").append(this.win);
this.win.append("<div id='TB_closeAjaxWindow' style='cursor:move' onmousedown='drag(this.parentNode,event);'><span id='TB_close'>X</span><span id='TB_title'>"+opt.title+"</span></div><div id='TB_ajaxContent'></div>");
$("#TB_close").click(function(){
that.hideWin();
});
}
this._init(opt);
$("#TB_ajaxContent").load(opt.url, function() {
that._hideAjaxLoad();
that.win.slideDown("normal");
});
},
hideWin:function(){
var that=this;
this.win.fadeOut("fast",function(){
that._hideCoverLayer();
});
},
_init:function(opt){
$("#TB_title").html(opt.title);
var top=opt.top || ( $(window).height() - opt.height ) /2+(opt.fixTop || 0);// +$(window).scrollTop() ;
var left=( $(window).width() - opt.width ) / 2+(opt.fixLeft || 0);//+$(window).scrollLeft();
this.win.css({"height":opt.height+"px",
"width":opt.width+"px",
"top":top+"px",
"left":left+"px"
});
},
reLoad:function(opt){//加載新頁(yè)面
var that=this;
this.win.fadeOut("fast",function(){
that._showAjaxLoad(that.imgUrl);
that._init(opt);
$("#TB_ajaxContent").load(opt.url, function() {
that._hideAjaxLoad();
that.win.fadeIn("normal");
});
});
}
}
})(jQuery);
CSS代碼如下:
body {background-color:#fff;}
html, body {height:100%;}
html body{font:12px Arial, Helvetica, sans-serif;color:#333333}
html>body{font:12px Arial, Helvetica, sans-serif;color:#333333}
#TB_overlay {
position: absolute;
top: 0;
left: 0;
z-index:100;
width: 100%;
height: 100%;
background-color:#CCC;
filter:alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
}
#TB_window {
top: 0px;
left: 0px;
position: fixed;
_position: absolute;
background: #fff;
z-index: 102;
color:#000000;
display:none;
border:5px solid #666;
}
#TB_caption{
height:25px;
padding:10px 30px 10px 25px;
}
#TB_closeWindow{
height:25px;
padding:10px 25px 10px 0;
float:right;
}
#TB_closeAjaxWindow{
padding:5px 10px 7px 0;
margin-bottom:1px;
text-align:right;
background-color:#e8e8e8;
}
#TB_close{
cursor:pointer;
}
#TB_title{
float: left;
font-weight: bold;
margin-left: 10px;
}
#TB_ajaxContent{
padding:2px 15px 15px 15px;
overflow:auto;
}
#TB_load{
text-align: center;
position: fixed;
top: 50%;
left: 0px;
width: 100%;
overflow: visible;
visibility: visible;
display: block;
z-index:101;
}
/*Download by http://sc.xueit.com*/
#TB_loadContent{
margin-left: -125px;
position: absolute;
top: -50px;
left: 50%;
width: 250px;
height: 100px;
visibility: visible;
}
這樣來(lái)使用:
$.module.showWin({url:"/deposit/clear/"+depositId+"?"+(+new Date),
title:"清退關(guān)閉",
width:550,
height:350});
效果如下:

關(guān)閉的時(shí)候,這樣調(diào)用:
$.module.hideWin();
這個(gè)彈出層有幾個(gè)問(wèn)題:
1、因?yàn)椴捎玫氖?.load()的方式,所以只能加載同源的url
2、在單頁(yè)面的情況下,可以很好的定位,如果作為在iframe中彈出,則需要傳入top值來(lái)輔助定位。這個(gè)問(wèn)題是因?yàn)?(window).top()在單頁(yè)面下和iframe下取的值不一樣導(dǎo)致的,也不知該怎么解決。有了解的朋友說(shuō)一下,不勝感激。
- js寫(xiě)一個(gè)彈出層并鎖屏效果實(shí)現(xiàn)代碼
- js實(shí)現(xiàn)div彈出層的方法
- 使用js實(shí)現(xiàn)關(guān)閉js彈出層的窗口
- js 點(diǎn)擊頁(yè)面其他地方關(guān)閉彈出層(示例代碼)
- js與css實(shí)現(xiàn)彈出層覆蓋整個(gè)頁(yè)面的方法
- js+css 實(shí)現(xiàn)遮罩居中彈出層(隨瀏覽器窗口滾動(dòng)條滾動(dòng))
- Js制作簡(jiǎn)單彈出層DIV在頁(yè)面居中 中間顯示遮罩的具體方法
- Js Jquery創(chuàng)建一個(gè)彈出層可加載一個(gè)頁(yè)面
- html+javascript實(shí)現(xiàn)可拖動(dòng)可提交的彈出層對(duì)話框效果
- js彈出層永遠(yuǎn)居中實(shí)現(xiàn)思路及代碼
- js setTimeout實(shí)現(xiàn)延遲關(guān)閉彈出層
- MC Dialog js彈出層 完美兼容多瀏覽器(5.6更新)
- JS實(shí)現(xiàn)的添加彈出層并完成鎖屏操作示例
相關(guān)文章
ES6模板字符串和標(biāo)簽?zāi)0宓膽?yīng)用實(shí)例分析
這篇文章主要介紹了ES6模板字符串和標(biāo)簽?zāi)0宓膽?yīng)用,結(jié)合實(shí)例形式分析了ES6模板字符串和標(biāo)簽?zāi)0宓墓δ?、原理、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-06-06Object.defineProperty()函數(shù)之屬性描述對(duì)象
這篇文章主要介紹了Object.defineProperty()函數(shù)之屬性描述對(duì)象,JavaScript?提供了一個(gè)內(nèi)部數(shù)據(jù)結(jié)構(gòu),用來(lái)描述對(duì)象的屬性,控制它的行為,比如該屬性是否可寫(xiě)、可遍歷等等。這個(gè)內(nèi)部數(shù)據(jù)結(jié)構(gòu)稱(chēng)為:屬性描述對(duì)象2022-09-09JavaScript中實(shí)現(xiàn)sprintf、printf函數(shù)
這篇文章主要介紹了JavaScript中實(shí)現(xiàn)sprintf、printf函數(shù),這兩個(gè)函數(shù)在大多數(shù)編程語(yǔ)言中都有,但JS中卻沒(méi)有,本文介紹在js中實(shí)現(xiàn)這兩個(gè)函數(shù)功能,需要的朋友可以參考下2015-01-01在layer彈層layer.prompt中,修改placeholder的實(shí)現(xiàn)方法
今天小編大家分享一篇在layer彈層layer.prompt中,修改placeholder的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09JavaScript實(shí)現(xiàn)瀑布動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)瀑布動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06JavaScript中的call和apply的用途以及區(qū)別
本文主要介紹了JavaScript中的call和apply的用途以及區(qū)別。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01javascript實(shí)現(xiàn)避免頁(yè)面按鈕重復(fù)提交
很多時(shí)候我們都需要防止重復(fù)提交,這方面的文章也比較多,實(shí)現(xiàn)的途徑差別也很大.因?yàn)橛行r(shí)候即使服務(wù)器能夠識(shí)別重復(fù)的提交,也會(huì)造成問(wèn)題.比如需要很長(zhǎng)等待時(shí)間的操作,在首次提交后,不斷重復(fù)提交,頁(yè)面可能會(huì)死掉.用腳本來(lái)控制的話可以防止這種問(wèn)題.2015-01-01js支持鍵盤(pán)控制的左右切換立體式圖片輪播效果代碼分享
這篇文章主要介紹了js支持鍵盤(pán)控制的左右切換立體式圖片輪播效果,很實(shí)用的代碼,推薦給大家,有需要的小伙伴可以參考下。2015-08-08