How to disable scrolling the document body?

前端 未结 6 522
一整个雨季
一整个雨季 2020-12-28 15:14

I have a HTML which has lot of content and a vertical scrollbar appears as soon as the HTML is loaded. Now from this HTML a full screen IFRAME is loaded. The problem is when

6条回答
  •  青春惊慌失措
    2020-12-28 15:49

    I know this is an ancient question, but I just thought that I'd weigh in.

    I'm using disableScroll. Simple and it works like in a dream.

    I have had some trouble disabling scroll on body, but allowing it on child elements (like a modal or a sidebar). It looks like that something can be done using disableScroll.on([element], [options]);, but I haven't gotten that to work just yet.


    The reason that this is prefered compared to overflow: hidden; on body is that the overflow-hidden can get nasty, since some things might add overflow: hidden; like this:

    ... This is good for preloaders and such, since that is rendered before the CSS is finished loading.

    But it gives problems, when an open navigation should add a class to the body-tag (like ). And then it turns into one big tug-of-war with overflow: hidden; !important and all kinds of crap.

提交回复
热议问题