Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent scroll of the page if pop-up is open

I am using the jquery mobile pop up. This is inside the page. There is an image that opens this pop-up. Now how do I prevent the entire page from scrolling only if the pop-up is open and allow scrolling if the pop up is closed?

    <a href="#settingsPopUp" data-rel="popup" data-position-to="window" data-inline="true" data-icon="gear"><img src="settings1.jpg" alt="Settings"></a>

    <br>
    <div data-role="popup" id="settingsPopUp" data-theme="a" class="ui-corner-all">
        <div style="padding:10px 20px;">
            <h3>Location Details</h3>               
        </div>          
    </div>
like image 372
Pramod Setlur Avatar asked Dec 08 '22 17:12

Pramod Setlur


1 Answers

I have mixed Lefois's solution and Simona Adriani's solution. It works for me in browser and mobile phone WebView (PhoneGap + jquerymobile).

$(document).on('popupafteropen', '[data-role="popup"]', function(event, ui) {
    $('body').css('overflow', 'hidden').on('touchmove', function(e) {
         e.preventDefault();
    });
}).on('popupafterclose', '[data-role="popup"]', function(event, ui) {
    $('body').css('overflow', 'auto').off('touchmove');
});
like image 183
oriolparra Avatar answered Dec 11 '22 12:12

oriolparra