bootstrap實(shí)現(xiàn)嵌套模態(tài)框的實(shí)例代碼
項(xiàng)目上有一個(gè)需求,需要在已經(jīng)彈出的一個(gè)bootstrap模態(tài)框的基礎(chǔ)上再?gòu)椧粋€(gè)模態(tài)框。
因?yàn)閎ootstrap官方不建議這么做,最后實(shí)現(xiàn)的過(guò)程屬實(shí)不易。
以下是解決方案:
html代碼:
<div id="container">
<a data-toggle="modal" href="#myModal" rel="external nofollow" class="btn btn-primary">彈出第一層模態(tài)框</a>
<!-- 第一層模態(tài)框 -->
<div class="modal fade" id="myModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">第一層模態(tài)框</h4>
</div>
<div class="container"></div>
<div class="modal-body">
<p>第一層模態(tài)框</p>
<br>
<a data-toggle="modal" href="#myModal2" rel="external nofollow" class="btn btn-primary">彈出第二層模態(tài)框</a>
</div>
<div class="modal-footer"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-dismiss="modal" class="btn">關(guān)閉</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-primary">保存</a>
</div>
</div>
</div>
</div>
<!-- 第二層模態(tài)框 -->
<div class="modal fade rotate" id="myModal2">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">第二層模態(tài)框</h4>
</div>
<div class="container"></div>
<div class="modal-body">
<p>第二層模態(tài)框</p>
</div>
<div class="modal-footer">
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-dismiss="modal" class="btn">關(guān)閉</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-primary">保存</a>
</div>
</div>
</div>
</div>
<!-- 遮罩 -->
<div id="cover"></div>
</div>
遮罩的css樣式:
<style type="text/css">
<!-- 遮罩是為了第二層模態(tài)框彈出時(shí),可以將第一層模態(tài)框遮住 -->
#cover {
display: none;
position: fixed;
background: #000000;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0.40;
z-index: 1
}
</style>
js代碼:
$(document).ready(function (){
//第二層模態(tài)框彈出時(shí),為其設(shè)置一個(gè)大于第一層模態(tài)框的z-index
//使得第二層模態(tài)框可以在第一層模態(tài)框上面
$(document).on('show.bs.modal', '#myModal2', function (event) {
var zIndex = 1040 + (10 * $('.modal:visible').length+1);
$(this).css('z-index', zIndex);
//開(kāi)啟遮罩,遮罩的高度小于第二層模態(tài)框
$("#cover").css('z-index',zIndex-1)
$('#cover').css('display','block'); //顯示遮罩層
});
$('#myModal2').on('hide.bs.modal', function() {
//第二層模態(tài)框關(guān)閉時(shí),關(guān)閉遮罩
$('#cover').css('display','none');
});
});
總結(jié)
以上所述是小編給大家介紹的bootstrap實(shí)現(xiàn)嵌套模態(tài)框的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
實(shí)例解析ES6 Proxy使用場(chǎng)景介紹
本篇文章主要介紹了ES6 Proxy使用場(chǎng)景介紹,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
原生JS實(shí)現(xiàn)簡(jiǎn)單的無(wú)縫自動(dòng)輪播效果
輪播效果是老生常談的話題,今天小編通過(guò)實(shí)例代碼給大家分享原生JS實(shí)現(xiàn)簡(jiǎn)單的無(wú)縫自動(dòng)輪播效果,感興趣的朋友跟隨小編一起學(xué)習(xí)吧2018-09-09
JS實(shí)現(xiàn)動(dòng)態(tài)修改table及合并單元格的方法示例
這篇文章主要介紹了JS實(shí)現(xiàn)動(dòng)態(tài)修改table及合并單元格的方法,結(jié)合完整實(shí)例形式分析了JS動(dòng)態(tài)遍歷及修改table單元格的具體操作技巧,需要的朋友可以參考下2017-02-02
Javascript中設(shè)置默認(rèn)參數(shù)值示例
這篇文章主要介紹了Javascript中默認(rèn)參數(shù)值的設(shè)置,很簡(jiǎn)單,但很實(shí)用,需要的朋友可以參考下2014-09-09
JavaScript表單驗(yàn)證實(shí)現(xiàn)過(guò)程詳解
表單校驗(yàn)是注冊(cè)環(huán)節(jié)中必不可少的操作,表單校驗(yàn)通過(guò)一定的規(guī)則來(lái)確保用戶提交數(shù)據(jù)的有效性,下面這篇文章主要給大家介紹了關(guān)于el-form表單驗(yàn)證的一些實(shí)用方法,需要的朋友可以參考下2023-01-01
認(rèn)識(shí)Knockout及如何使用Knockout綁定上下文
Knockout簡(jiǎn)稱ko,是一個(gè)輕量級(jí)的javascript類庫(kù),采用MVVM設(shè)計(jì)模式(即Model、view、viewModel),簡(jiǎn)單優(yōu)雅的實(shí)現(xiàn)了雙向綁定,實(shí)時(shí)更新,幫助您使用干凈的數(shù)據(jù)模型來(lái)創(chuàng)建豐富的、響應(yīng)式的用戶界面2015-12-12

