+ 1

Scroll event not working horizontally

I have a code with window.onscroll, but if I change the width of the document to enable horizontal scrolling (remove // in JS line 5), the scroll event stops firing altogether. https://code.sololearn.com/WreJnlyKVNq5/?ref=app

15th Jul 2023, 6:49 PM
C. Scheler
C. Scheler - avatar
7 Answers
+ 4
Abdun Nur Porag When you copy text from ChatGPT and Co., you are required to cite your sources properly
17th Jul 2023, 7:24 PM
Lisa
Lisa - avatar
+ 2
The scroll event is working, but because the body width is larger than the screen width, the app is actually scrolling over the document instead of the doc scrolling over its contents. (If that makes sense đŸ€”) If you change both the width and the height of the body to 3000px, you'll see effects you expected as scroll closer to one end or the other. It's rare to see the body wider the screen on mobile devices. Creating a div where the width and height are larger, then the body's width and height should result in the desired effects. You will need to use scrollTop and scrollLeft
19th Jul 2023, 1:23 PM
ODLNT
ODLNT - avatar
0
What was supposed to happend when you scroll on x?
15th Jul 2023, 9:07 PM
Anton Drud
Anton Drud - avatar
0
Anton Drud The background color should change. The thing is, the scroll event isn't even triggered.
15th Jul 2023, 9:10 PM
C. Scheler
C. Scheler - avatar
0
I am pretty sure it is because there is nothing to scroll on, on the x axis. But im not 100% sure. Have you tried drag events.
16th Jul 2023, 9:44 AM
Anton Drud
Anton Drud - avatar
0
Abdun Nur Porag What do you mean? I haven't used scrollTop in my code, I used scrollX and scrollY. Also, I don't have a progress bar. The problem is not within the onscroll function because if you replace the code in the function with "console.log('.')", you'll see that it still doesn't do anything.
17th Jul 2023, 7:20 PM
C. Scheler
C. Scheler - avatar
0
Sorry,i can not write my full code and information here
17th Jul 2023, 7:22 PM
Abdun Nur Porag
Abdun Nur Porag - avatar