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>
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');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With