国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Bootstrap模態框水平垂直居中與增加拖拽功能

2019-11-19 19:00:03
字體:
來源:轉載
供稿:網友

最近開發一個CMS系統使用上了Bootstrap,在開發一個添加某些選項時,打算彈出一個模態框,但是發現,模態框不會垂直居中到屏幕上,而是在屏幕上方,找了好多資料都沒搞定,最終自己試出了一種JS的方法,同時還需要Bootstrap模態框可以拖動,但是發現默認的也不行,翻遍了網絡找了出來。現在分享給大家:

原文地址:http://www.panshy.com/articles/201509/webdev-2524.html

以下為Bootstrap模態框拖拽功能的增加方法

$("#myModal").draggable({ handle: ".modal-header", cursor: 'move', refreshPositions: false }); 

handle: ".modal-header", 去除將可以整個模態框都可以拖動,其中modal-header代表拖動的DIV的CLASS或ID

以下為彈出Bootstrap模態框水平垂直居中的代碼

/* 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); 代表用戶改變瀏覽器時的事件,可以不用,但是改變瀏覽器,模態框不會跟著變化。

以上的JS代碼加到頁面的最后即可

Bootstrap模態框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">標題</h4> </div> <div style="padding:5px;"> <div class="modal-body" data-scrollbar="true" data-height="200" data-scrollcolor="#000"> 

模態框內容

</div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">關閉</button> </div> </div> </div> </div> 

Bootstrap模態框水平垂直居中與增加拖拽功能.png

以上所述是小編給大家介紹的Bootstrap模態框水平垂直居中與增加拖拽功能,實現一個模擬后臺數據登入的效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高邮市| 景东| 崇左市| 沿河| 乐安县| 滦平县| 汝阳县| 汤原县| 武冈市| 中超| 阳曲县| 新余市| 和平县| 水富县| 云南省| 永福县| 伊金霍洛旗| 来凤县| 牙克石市| 翼城县| 灵台县| 开平市| 安泽县| 内丘县| 荆州市| 西城区| 庆阳市| 玉林市| 修水县| 商都县| 延寿县| 乌海市| 来宾市| 北安市| 河源市| 桃园市| 新密市| 珠海市| 巴塘县| 新绛县| 漠河县|