jQuery DIV彈出效果實(shí)現(xiàn)代碼
先上個(gè)效果圖,可以點(diǎn)擊Close按鈕或是在遮罩層上任意處點(diǎn)擊,就可以關(guān)閉彈出層。
HTML代碼
<div id='pop-div' style="width: 300px" class="pop-box" >
<h4>標(biāo)題位置</h4>
<div class="pop-box-body" >
<p>
正文內(nèi)容
</p>
</div>
<div class='buttonPanel' style="text-align: right" style="text-align: right">
<input value="Close" id="btn1" onclick="hideDiv('pop-div');" type="button" />
</div>
</div>
代碼很簡潔。最外層是一個(gè)大的DIV作為彈出層的容器,H4作為彈出層的標(biāo)題,又一個(gè)DIV用于彈出層正文內(nèi)容顯示,再一個(gè)Div用于放置一些按鈕。
CSS代碼
.pop-box {
z-index: 9999; /*這個(gè)數(shù)值要足夠大,才能夠顯示在最上層*/
margin-bottom: 3px;
display: none;
position: absolute;
background: #FFF;
border:solid 1px #6e8bde;
}
.pop-box h4 {
color: #FFF;
cursor:default;
height: 18px;
font-size: 14px;
font-weight:bold;
text-align: left;
padding-left: 8px;
padding-top: 4px;
padding-bottom: 2px;
background: url("../images/header_bg.gif") repeat-x 0 0;
}
.pop-box-body {
clear: both;
margin: 4px;
padding: 2px;
}
JS代碼
function popupDiv(div_id) {
var div_obj = $("#"+div_id);
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = div_obj.height();
var popupWidth = div_obj.width();
//添加并顯示遮罩層
$("<div id='mask'></div>").addClass("mask")
.width(windowWidth * 0.99)
.height(windowHeight * 0.99)
.click(function() {hideDiv(div_id); })
.appendTo("body")
.fadeIn(200);
div_obj.css({"position": "absolute"})
.animate({left: windowWidth/2-popupWidth/2,
top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
}
function hideDiv(div_id) {
$("#mask").remove();
$("#" + div_id).animate({left: 0, top: 0, opacity: "hide" }, "slow");
}
- 使用jQueryMobile實(shí)現(xiàn)滑動翻頁效果的方法
- 基于jquery的橫向滾動條(滑動條)
- jQuery控制的不同方向的滑動(向左、向右滑動等)
- jQuery點(diǎn)擊后一組圖片左右滑動的實(shí)現(xiàn)代碼
- JQuery Dialog(JS 模態(tài)窗口,可拖拽的DIV)
- 基于jquery的模態(tài)div層彈出效果
- 使用jquery實(shí)現(xiàn)div的tab切換實(shí)例代碼
- jquery鼠標(biāo)放上去顯示懸浮層即彈出定位的div層
- jquery獲取div寬度的實(shí)現(xiàn)思路與代碼
- 移動端jQuery修正Web頁面滑動時(shí)div問題的兩則實(shí)例
相關(guān)文章
jQuery動態(tài)產(chǎn)生select option下拉列表
這篇文章主要介紹了jQuery動態(tài)產(chǎn)生select option下拉列表的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-03-03jQuery form插件之a(chǎn)jaxForm()和ajaxSubmit()的可選參數(shù)項(xiàng)對象
這篇文章主要介紹了jQuery form插件之a(chǎn)jaxForm()和ajaxSubmit()的可選參數(shù)項(xiàng)對象的相關(guān)資料,需要的朋友可以參考下2016-01-01jQuery調(diào)取jSon數(shù)據(jù)并展示的方法
這篇文章主要介紹了jQuery調(diào)取jSon數(shù)據(jù)并展示的方法,實(shí)例分析了jQuery調(diào)用json數(shù)據(jù)及展示的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01JQuery實(shí)現(xiàn)表格數(shù)據(jù)行上移與下移
這篇文章主要為大家詳細(xì)介紹了JQuery實(shí)現(xiàn)表格數(shù)據(jù)行上移與下移,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02在一個(gè)頁面實(shí)現(xiàn)兩個(gè)zTree聯(lián)動的方法
最近發(fā)現(xiàn)項(xiàng)目中很多地方都是樹形菜單,而這些樹形菜單都是使用樹形插件zTree來制作的,下面這篇文章主要給大家介紹了關(guān)于在一個(gè)頁面實(shí)現(xiàn)兩個(gè)zTree聯(lián)動的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12jQuery Validate表單驗(yàn)證入門學(xué)習(xí)
這篇文章主要介紹了jQuery Validate表單驗(yàn)證入門知識,該插件捆綁了一套有用的驗(yàn)證方法,包括 URL 和電子郵件驗(yàn)證,同時(shí)提供了一個(gè)用來編寫用戶自定義方法的 API,感興趣的小伙伴們可以參考一下2015-12-12