How to prevent background scrolling when Bootstrap 3 modal open on mobile browsers?

后端 未结 20 1431
抹茶落季
抹茶落季 2020-12-01 01:45

How to prevent background scrolling when Bootstrap 3 modal open on mobile platforms? On desktop browsers the background is prevented from scrolling and works as it should.<

20条回答
  •  眼角桃花
    2020-12-01 01:57

    No scripts needed.

    BS 3 sets a .modal-open class on body that you can use to set the position and overflow values (made with LESS).

    body {
        font-family:'Open Sans';
        margin:0;
    
        &.modal-open {
            position:fixed;
            overflow:hidden;
    
            .modal { 
                overflow: scroll;
    
                @media only screen and (min-resolution:150dpi) and (max-width: @screen-sm),
                only screen and (-webkit-min-device-pixel-ratio:1.5) {
                    overflow: scroll; 
                    -webkit-overflow-scrolling: touch; 
                }
            }
        }   
    }
    

提交回复
热议问题