Realize the effect that the background cannot slide after the pop-up box of the webpage

We often write effects such as the pop-up box of the mask layer, but the editor recently found that after the pop-up box appears, the background content information it covers can slide, and the experience is very bad, so how to prohibit the background sliding

very simple property


After the popup appears, set the body to hidden
document.body.style.overflow = "hidden";

body is set to auto when the popup is closed
document.body.style.overflow = "hidden"; 


This can achieve the effect, generally it is dynamically added
to set the overflow property of the body according to your event requirements.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324985361&siteId=291194637