Bootstrap對話框改變其默認寬高,高度不會自適應居中。爲解決這個問題,最好的方式是可以經過css來解決,試了幾種網上的方案發現都不行。而後想到能夠經過js來修正,何時修正最好?因而想到能夠註冊全局的事件。javascript
下表是Bootstrap官方的事件。css
Event Type | Description |
---|---|
show.bs.popover | This event fires immediately when the show instance method is called. |
shown.bs.popover | This event is fired when the popover has been made visible to the user (will wait for CSS transitions to complete). |
hide.bs.popover | This event is fired immediately when the hide instance method has been called. |
hidden.bs.popover | This event is fired when the popover has finished being hidden from the user (will wait for CSS transitions to complete). |
inserted.bs.popover | This event is fired after the show.bs.popover event when the popover template has been added to the DOM. |
$('#myPopover').on('hidden.bs.popover', function () { // do something… })
可是,我使用的是$(aa).modal('show'),因此改爲這樣:
$(function () { //修正modal彈窗高度不能自適應的問題 $('body .modal').on('show.bs.modal', function () { var $cur = $(this); $cur.css("top", ($(window).height() - $cur.height()) / 2); }); });