Prevent jQuery from jumping to the bottom (when using fadeIn)
I've created some divs fading in with jQuery, I have a problem if the user scrolls a bit down though. If you are not at the top of the page, it will always jump to the bottom when a new div fades in.
Here's my code:
- <style>
- #overflowwrap {
- overflow:hidden !important;
- }
- </style>
- <div style="height:20px">header stuff</div>
- <div id="overflowwrap">
- <div id="five" style="display:none;">a lot of content 5</div>
- <div id="four" style="display:none;">a lot of content 4</div>
- <div id="three" style="display:none;">a lot of content 3</div>
- <div id="two" style="display:none;">a lot of content 2</div>
- <div id="one" style="display:none;">a lot of content 1</div>
- </div>
- <div style="height:20px">footer stuff</div>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- <script>
- $('#overflowwrap').css('max-height',$(window).height());
- $("#one").fadeIn(500);
- setTimeout( function show() {
- $("#two").fadeIn(500);
- }, 5000);
- setTimeout( function show() {
- $("#three").fadeIn(500);
- }, 10000);
- setTimeout( function show() {
- $("#four").fadeIn(500);
- }, 15000);
- setTimeout( function show() {
- $("#five").fadeIn(500);
- }, 20000);
- </script>
This wouldn't be a problem, if the #overflowwrap div was the only element on a page and the user couldn't scroll. However, it's integrated on another site (survey software with "header/footer stuff"), so the user is able to scroll.
Is there anything I can do to prevent the site from jumping to the bottom?