Twitter bootstrap scrollable modal

前端 未结 10 1140
日久生厌
日久生厌 2020-12-22 19:03

I\'m using twitter bootstrap for a project I am working on.

I have a modal window that has a somewhat longer form in it and I didn\'t like that when the window got

10条回答
  •  一向
    一向 (楼主)
    2020-12-22 19:57

    In case of using .modal {overflow-y: auto;}, would create additional scroll bar on the right of the page, when body is already overflowed.

    The work around for this is to remove overflow from the body tag temporarily and set modal overflow-y to auto.

    Example:

    $('.myModalSelector').on('show.bs.modal', function () {
    
            // Store initial body overflow value
            _initial_body_overflow = $('body').css('overflow');
    
            // Let modal be scrollable
            $(this).css('overflow-y', 'auto');
            $('body').css('overflow', 'hidden');
    
    
        }).on('hide.bs.modal', function () {
    
            // Reverse previous initialization
            $(this).css('overflow-y', 'hidden');
            $('body').css('overflow', _initial_body_overflow);
    });
    

提交回复
热议问题