简体   繁体   English

模态窗口打开时锁定页面滚动

[英]Lock the page scroll when modal window opened

How do I stop scrolling when a modal window is opened 打开模式窗口时如何停止滚动

I call the modal window in so many places that the window is calling some other function. 我在很多地方都调用了模式窗口,以至于窗口正在调用其他函数。 At the time the modal window appears the page scrolls creates a problem going up. 在模式窗口出现时,页面滚动会导致问题上升。

I want to fix the position of scrolling when modal window is called or any modal window function is called. 我想固定在调用模式窗口或调用任何模式窗口函数时滚动的位置。

So basically I wrote one scroll event to control the scrolling but it is going up only. 因此,基本上,我编写了一个滚动事件来控制滚动,但这只是上升。 I want to be fixed the position of scroll bar in same when its called the modal window. 我想将滚动条的位置固定为模态窗口时的位置。

 document.body.scrollTop     = 0;

Check if your modal adds any class to body element. 检查您的模态是否将任何类添加到body元素。 If so, just apply overflow: hidden to this class. 如果是这样,只需将overflow: hidden到此类。 Else, when opening modal, add some class to body element manually and apply same overflow. 否则,在打开模态时,手动将一些类添加到body元素并应用相同的溢出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM