LoginSignup
0
3

More than 5 years have passed since last update.

bootstrap3 modal 背景をスクロールさせない

Last updated at Posted at 2018-03-29

modalを使うと、背景がスクロールしてしまう。
これはご遠慮願いたい。


<script>
var current_scrollY;
    $(function () {
    //    modalを開いた時
        $('#profile-modal').on('shown.bs.modal', function (event) {
            current_scrollY = $( window ).scrollTop();
            $('body').css( {
                position: 'fixed',
                width: '100%',
                top: -1 * current_scrollY
            } );
        });

        //  modalを閉じた時
        $('#profile-modal').on('hidden.bs.modal', function (event) {
            $( 'body' ).attr( { style: '' } );
            $( 'html, body' ).prop( { scrollTop: current_scrollY } );
        });

    });


</script>

これでOK

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3