Prevent Background Scrolling When Displaying Popup

前端 未结 5 1344
名媛妹妹
名媛妹妹 2020-12-25 13:17

I have a form that is displayed in a popup. After loading, the background is grayed out, but the user can still scroll the background content up and down.

How do I

5条回答
  •  生来不讨喜
    2020-12-25 13:57

    This code block works for IOS mobile devices where the scroll issue is very common.

    $('body').on('touchmove', function(e) {
        if ($('.scroll-disable').has($(e.target)).length) e.preventDefault();
    });
    $('body').on('shown.bs.modal', function() {
        $(this).addClass('scroll-disable');
    });
    $('body').on('hidden.bs.modal', function() {
        $(this).removeClass('scroll-disable');
    });
    

提交回复
热议问题