body { overflow: hidden; } [1 SOLUTION] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

body { overflow: hidden; } [1 SOLUTION]

I have a code I'm working on and found a strange behavior happening. I don't know whether it's SoloLearn on mobile or not, but that's where this weird "bug" is happening. Here is the code I wrote that has this behavior: https://code.sololearn.com/Wh117ebi576o in the CSS, the main focus is the modal I made with the id's #modalContainer and #searhModal. When the search icon is clicked, I trigger some jQuery javascript: $("#searchIcon").click(event => { screenH = window.innerHeight; $("#modalContainer").css({"height": screenH + "px", "display": "block"}); $("body").css("overflow", "hidden"); }); The goal is to set the modal containers height to the screen height and display it. Simultaneously, I set the body's overlow to hidden so that when the user scrolls to the bottom of the modal, it wont scroll past it into the rest of the page's content (what's the point of a modal if that happens, right?). When the modal is exited (upon clicking the 'X' in the modal), the modal containers display is n

17th Oct 2018, 2:28 AM
Zeke Williams
Zeke Williams - avatar
2 Answers
+ 4
That is a weird behaviour. But i found a hacky fix. You might like it. Instead of overflow:hidden use position:fixed i.e. first: $("body").css("position", "fixed"); then: $("body").css("position", "initial"); after modal close
17th Oct 2018, 2:45 AM
Niush
Niush - avatar
+ 3
Niush sitaula thanks! That seems to work fine for now. Hopefully future updates don't clash with it :)
17th Oct 2018, 3:13 AM
Zeke Williams
Zeke Williams - avatar