I would do something similar for a modal div:
<div style="background-color: rgba(255,255,255, 0.93);position:fixed;
overflow-x:auto;overflow-y:scroll;bottom:0;left:0;right:0;top:0;
z-index:9999;"></div>
Creates a div that fills the entire document, and then adds a scroll bar for the middle content. Once you show the modal, you need to install the main body (background) of your page:
style="overflow:hidden"
You can use jquery, for example:
$("body").css("overflow", "hidden");
It is important that the main body set the overflow to hidden to remove another scrollbar. When I tested this in Firefox, it worked. I had a div as described, and then set the body style, and it worked. I was also in the middle of the document when I tested it. The background document remained where it was and did not move.
source
share