To view the code as a reference, click here.
After pressing the button, the state changes and #container1 gets replaced with #container2. Despite this change, the page height remains constant and the outer containers maintain their original height. However, when scrolling down to reach the button and then pressing it, the page jumps up to the middle unexpectedly. It's puzzling because no layout adjustments were made, only the text was altered.
I'm trying to ensure that the container heights remain fixed even when the text inside overflows. The issue seems to be related to the overflow causing this sudden page jump problem.
Here are some interesting observations:
- The bug doesn't occur if #container2 contains only 1 div element.
- This bug occurs only on the initial transition from #container1 to #container2. Subsequent transitions will trigger the issue if you have scrolled up while viewing #container1.
- The bug is reproducible in various modes like "Toggle Responsive Preview" for "Tablet" or "Desktop". However, opening the page in a new tab prevents the bug from appearing.
- While I noticed this bug primarily in Chrome, testing revealed that it also affects Firefox and Edge browsers.