I'm creating a webpage that has some off-screen content that only needs to slide in at specific times. To achieve this I'm setting overflow-x: hidden on html, body. This way the user cannot scroll left or right to get at the content.
However, at some point in the application I also need the amount that the user has scrolled down yet. As far as I know window.pageYOffset is one of the most reliable ways of doing this.
However, when I set the overflow-x rule. window.pageYOffset is always equal to 0.
Shouldn't these things be pretty unrelated to each other? How can I fix this?
I've tested this on Safari, Firefox and Chrome.
I've tried document.documentElement.scrollTop but this only worked on Firefox.
NB:
I was not able to reproduce the problem with a very simple example.
My app also has the main content in a container that has position: absolute. If I remove this, everything works.
So it seems to be the combination of overflow-x: hidden on body and postion: absolute on the .content inside the body.
I cannot easily get rid of the position absolute requirement however, since
different .content containers should be able to be placed over one another.
Edit 2:
It gets even weirder: I've got a transform: translate(0,0) set on .content to be be able to transition to some other value later. If I remove this, everything works fine! Yet another seemingly unrelated css
property that interferes.
overflow-x: hiddenon both html and body. If I moved it to just html, it was fine. However, IE11 would now ignore it, meaning I had to add an additionaloverflow-x: hiddento an internal element. As another note, it was due to adding flex and sticky footer stuff that caused this bug to manifest itself. Translates and position absolutes probably affect it too. - Matt Fletcher