I looked through a lot of answers regarding disabling body scrolling on iPads for modal, and none of them found suitable, especially when I have a scrollable div on modal, I found this javascript logic combination from another SO user , and then disconnecting the event handler from The pop-up closure did the trick.
In the popup menu / dialog box:
//uses document because document will be topmost level in bubbling $(document).on('touchmove', function (e) { e.preventDefault(); }); //uses body because jquery on events are called off of the element they are //added to, so bubbling would not work if we used document instead. $('body').on('touchstart', '.scrollable', function (e) { if (e.currentTarget.scrollTop === 0) { e.currentTarget.scrollTop = 1; } else if (e.currentTarget.scrollHeight === e.currentTarget.scrollTop + e.currentTarget.offsetHeight) { e.currentTarget.scrollTop -= 1; } }); //prevents preventDefault from being called on document if it sees a scrollable div $('body').on('touchmove', '.scrollable', function (e) { e.stopPropagation(); });
Enable popup / dialog:
$(document).off('touchmove'); $('body').off('touchstart', '.scrollable'); $('body').off('touchmove', '.scrollable');
The scrollable above simply allow the elements you require, the scroll will be freed from logic if the element has this css class.
In my case, I had a scrollable div inside my popup that caused all kinds of problems, so to turn off background scrolling but still allow scrolling in the dialog scrollable div, make sure you add the scrollable class to your scrollable div, so it is ignored.
source share