On refresh does not scroll up to top
See original GitHub issueHello 👋
Describe the bug When I refresh the page most of the time the current position is calculated as top of the page. To make it clear. If I scrolled down to half of the page and refresh it then the top of the page will be at the half of the page. I cannot scroll up but I can scroll down having blank section.
To Reproduce Here is my very basic structure
<div id="loco-scroll"> <div class="one vertical red" data-scroll data-scroll-speed="0" data-scroll-direction="vertical" ></div> <div class="two horizontal green" data-scroll data-scroll-speed="4" data-scroll-direction="horizontal" ></div> <div class="three horizontal blue" data-scroll data-scroll-speed="2" data-scroll-direction="horizontal" ></div> <div class="four horizontal yellow" data-scroll data-scroll-speed="2" data-scroll-direction="horizontal" ></div> <div class="five vertical orange" data-scroll data-scroll-speed="2" data-scroll-direction="vertical" ></div> </div> <script src="js/locomotive-scroll.js"></script> <script> const scroll = new LocomotiveScroll({ el: document.querySelector('#loco-scroll'), smooth: true, }); </script>
stylesheet `#loco-scroll div { width: 100vw; height: 100vh; }
.red { background-color: red; } .green { background-color: green; } .blue { background-color: blue; } .yellow { background-color: yellow; } .orange { background-color: orange; }`
Expected behavior Jump to top of the page
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: macOS Catalin v10.15.2
- Browser same thing happens in <del>Safari, Firefox,</del> Chrome
- Version latest
Thank you 👊
Laszlo
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:18 (1 by maintainers)
Top GitHub Comments
After testing some CSS, I found you need to set
width
andheight
inhtml, body
to properly work after refreshing the page.I have noticed this issue on Chrome. Firefox seems fine and always starts at the top of the page upon refreshing.
One way to counter this is to add a handler on the
onbeforeunload
event and force the window to go back to top with javascript like so :window.onbeforeunload = function () { window.scrollTo(0,0); };
Weirdly enough, it doesn’t seem to work on one of my coworker’s computer (Chrome)