关闭Bootstrap Dialog后,滚动条消失

时间:2015-03-30 17:28:34

标签: javascript html css twitter-bootstrap

我的网站有问题。我使用Bootstrap 3.2和Bootstrap Dialog而不是模态。当对话框打开时,有一个滚动条但关闭它会使滚动条消失。我已经阅读了很多主题,但我还没有找到合适的解决方案。有什么方法可以解决这个问题吗?

所以,这是我的对话框代码:

$("a.removeClass").click(function() {

        var uid = $(this).attr('id');   

        BootstrapDialog.show({
            message: 'Czy na pewno chcesz usunąć tą klasę?',
            title: 'Usuwanie klasy',
            buttons: [{
                label: 'Usuń klasę',
                cssClass: 'btn-danger',
                action: function(dialog) {
                    $(location).attr('href','index.php?app=admin&section=classes&uid=' + uid + '&remove');
                }
            }]
        });
    });

它也不起作用:How can I prevent body scrollbar and shifting when twitter bootstrap modal dialog is loaded?

1 个答案:

答案 0 :(得分:0)

将此添加到您的CSS:

.modal {
  overflow-y: auto;
}
/* custom class to add space for scrollbar */
.modal-scrollbar {
    margin-right: 15px;
}

这是你的JS:

(function($) {

$(document)
    .on( 'hidden.bs.modal', '.modal', function() {
        $(document.body).removeClass( 'modal-scrollbar' );
    })
    .on( 'show.bs.modal', '.modal', function() {
        // Bootstrap's .modal-open class hides any scrollbar on the body,
        // so if there IS a scrollbar on the body at modal open time, then
        // add a right margin to take its place.
        if ( $(window).height() < $(document).height() ) {
            $(document.body).addClass( 'modal-scrollbar' );
        }
    });

})(window.jQuery);

Via- How can I prevent body scrollbar and shifting when twitter bootstrap modal dialog is loaded?