I want to open a modal layer that overtakes body scrolling. To achieve this, when the layer is displayed, I set the overflow of the body to hidden, and the overflow to the modal layer. Visually, one scrollbar replaces another.
In the background, I have a top panel with a fixed position and a width of 100%. What happens when the overflow of the body is set to hidden, the width of 100% of the width (top panel) occupies the space of the scroll bar, and its elements move to the right.
How can I prevent these items from moving?
I tried to calculate (javascript) the width of the scrollbar and when setting the overflow of the body: hidden, enter margin-right: "width of the scrollbar" in the top panel. This did not work.
Also tried a dummy div at the right end of the top pane with the overflow set for scrolling, and made it display a scroll bar when opening the layer. The idea was to fill in the gap in the skipped scrollbar using another scrollbar, only on the top container. It almost worked, but created a flicker of 1 or 2px. Not enough.
jsBeginning here with the main problem
var body = $('body'), main = $('.main'), open_modal = $('.open-modal'), close_modal = $('.close-modal'), modal_container = $('.modal-container'), toggleModal = function() { body.toggleClass('body-locked'); modal_container.toggleClass('dp-block'); }; open_modal.on('click', toggleModal); close_modal.on('click', toggleModal);
javascript html css css3
ca2s7l
source share