I love jQuery UI dialogs. I hate when scrolling the dialogs’ content to the bottom starts scrolling the page underneath, moving the dialog off screen. With some smart structure of the page’s html, that can be avoided.
First, let’s show the problem. This is a basic page with a jQuery UI dialog shown. The dialog is modal, so it prevents access to the page behind. There are scroll bars on both the dialog and then page. Scrolling the dialog’s content with the mouse wheel works fine, until the bottom of the dialog is reached. At this point, I do expect continued rolling of the wheel to hit a dead end. Unfortunately it doesn’t. It starts scrolling the page behind the dialog instead. Rolling some more will eventually move the dialog off page, leaving the user with a large disabled area. That is definitely not a good user experience. Here is a small live demo.
The Body Scrolls
The problem appears because the jQuery UI dialog is just a cleverly designed div that is added dynamically to the end of the body. Pressing F12 on the live demo page shows that there is a
<div> right before the closing
</body> tag. That div is the jQuery UI dialog.
When hitting the bottom of the dialog it can no longer be scrolled. Instead the parent element – the entire
<body> is scrolled and the dialog moves off page. The solution is to no longer make the
<body> scrollable but instead move the scrolling to a separate