最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Bootstrap模態(tài)框水平垂直居中與增加拖拽功能

 更新時間:2016年11月09日 14:33:52   作者:一政  
最近開發(fā)一個CMS系統(tǒng)使用上了Bootstrap,在開發(fā)一個添加某些選項時,打算彈出一個模態(tài)框,但是發(fā)現(xiàn),模態(tài)框不會垂直居中到屏幕上,而是在屏幕上方,通過查閱資料才解決此問題,下面小編給大家分享解決思路

最近開發(fā)一個CMS系統(tǒng)使用上了Bootstrap,在開發(fā)一個添加某些選項時,打算彈出一個模態(tài)框,但是發(fā)現(xiàn),模態(tài)框不會垂直居中到屏幕上,而是在屏幕上方,找了好多資料都沒搞定,最終自己試出了一種JS的方法,同時還需要Bootstrap模態(tài)框可以拖動,但是發(fā)現(xiàn)默認(rèn)的也不行,翻遍了網(wǎng)絡(luò)找了出來。現(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", 去除將可以整個模態(tài)框都可以拖動,其中modal-header代表拖動的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覽器時的事件,可以不用,但是改變?yōu)g覽器,模態(tài)框不會跟著變化。

以上的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)框水平垂直居中與增加拖拽功能.png

以上所述是小編給大家介紹的Bootstrap模態(tài)框水平垂直居中與增加拖拽功能,實(shí)現(xiàn)一個模擬后臺數(shù)據(jù)登入的效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

沙河市| 元阳县| 贵南县| 呼图壁县| 中方县| 遂昌县| 瑞金市| 永仁县| 雅安市| 延长县| 巴林左旗| 蕲春县| 丹凤县| 观塘区| 清徐县| 顺昌县| 德惠市| 保定市| 双桥区| 蓬溪县| 黄龙县| 中牟县| 婺源县| 鄱阳县| 靖边县| 松阳县| 德江县| 田阳县| 湘阴县| 富阳市| 原平市| 同德县| 东兴市| 洪湖市| 峡江县| 正蓝旗| 于田县| 崇左市| 宝清县| 佛教| 仁怀市|