Bootstrap模態(tài)框水平垂直居中與增加拖拽功能
最近開發(fā)一個(gè)CMS系統(tǒng)使用上了Bootstrap,在開發(fā)一個(gè)添加某些選項(xiàng)時(shí),打算彈出一個(gè)模態(tài)框,但是發(fā)現(xiàn),模態(tài)框不會(huì)垂直居中到屏幕上,而是在屏幕上方,找了好多資料都沒搞定,最終自己試出了一種JS的方法,同時(shí)還需要Bootstrap模態(tài)框可以拖動(dòng),但是發(fā)現(xiàn)默認(rèn)的也不行,翻遍了網(wǎng)絡(luò)找了出來?,F(xiàn)在分享給大家:
原文地址:http://www.panshy.com/articles/201509/webdev-2524.html
以下為Bootstrap模態(tài)框拖拽功能的增加方法
$("#myModal").draggable({ handle: ".modal-header", cursor: 'move', refreshPositions: false });
handle: ".modal-header", 去除將可以整個(gè)模態(tài)框都可以拖動(dòng),其中modal-header代表拖動(dòng)的DIV的CLASS或ID
以下為彈出Bootstrap模態(tài)框水平垂直居中的代碼
/* center modal */ function centerModals() { $('#myModal').each(function(i) { var $clone = $(this).clone().css('display', 'block').appendTo('body'); var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2); top = top > 0 ? top : 0; $clone.remove(); $(this).find('.modal-content').css("margin-top", top); }); } $('#myModal').on('show.bs.modal', centerModals); $(window).on('resize', centerModals);
其中,$(window).on('resize', centerModals); 代表用戶改變?yōu)g覽器時(shí)的事件,可以不用,但是改變?yōu)g覽器,模態(tài)框不會(huì)跟著變化。
以上的JS代碼加到頁面的最后即可
Bootstrap模態(tài)框HTML
<!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <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" id="myModalLabel">標(biāo)題</h4> </div> <div style="padding:5px;"> <div class="modal-body" data-scrollbar="true" data-height="200" data-scrollcolor="#000">
模態(tài)框內(nèi)容
</div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</button> </div> </div> </div> </div>
以上所述是小編給大家介紹的Bootstrap模態(tài)框水平垂直居中與增加拖拽功能,實(shí)現(xiàn)一個(gè)模擬后臺(tái)數(shù)據(jù)登入的效果,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- BootStrap table實(shí)現(xiàn)表格行拖拽效果
- 詳解為Bootstrap Modal添加拖拽的方法
- 基于bootstrap的上傳插件fileinput實(shí)現(xiàn)ajax異步上傳功能(支持多文件上傳預(yù)覽拖拽)
- .net core版 文件上傳/ 支持批量上傳拖拽及預(yù)覽功能(bootstrap fileinput上傳文件)
- bootstrap模態(tài)框?qū)崿F(xiàn)拖拽效果
- JS組件Bootstrap Table表格多行拖拽效果實(shí)現(xiàn)代碼
- JS組件Bootstrap Table表格行拖拽效果實(shí)現(xiàn)代碼
- BootStrap modal實(shí)現(xiàn)拖拽功能
相關(guān)文章
Layui 導(dǎo)航默認(rèn)展開和菜單欄選中高亮設(shè)置的方法
今天小編就為大家分享一篇Layui 導(dǎo)航默認(rèn)展開和菜單欄選中高亮設(shè)置的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09BootStrap modal實(shí)現(xiàn)拖拽功能
這篇文章主要為大家詳細(xì)介紹了BootStrap modal實(shí)現(xiàn)拖拽功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12JavaScript斷言與類型守衛(wèi)及聯(lián)合聲明超詳細(xì)介紹
這篇文章主要介紹了JavaScript斷言與類型守衛(wèi)及聯(lián)合聲明,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-11-11select標(biāo)簽設(shè)置默認(rèn)選中的選項(xiàng)方法
下面小編就為大家分享一篇select標(biāo)簽設(shè)置默認(rèn)選中的選項(xiàng)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03