question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On refresh does not scroll up to top

See original GitHub issue

Hello 👋

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:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

25reactions
podrivocommented, Feb 29, 2020

After testing some CSS, I found you need to set width and height in html, body to properly work after refreshing the page.

html, body {
   width: 100vw;
   height: 100vh;
}
12reactions
maximeDorecommented, Jan 31, 2020

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Force page scroll position to top at page refresh in HTML
Instead of location.reload() , simply use location.href = location.href . It will not scroll to the previous position as location.reload() ...
Read more >
JavaScript: Force Scroll to the Top of Page on Refresh
Ensure that the browser scrolls to the top of the page when the page is refreshed.
Read more >
JavaScript - scroll to top page after page refresh - Dirask
In this article, we're going to have a look at how using JavaScript, scroll the page to the top after the refresh operation...
Read more >
Scroll to the top of the page using JavaScript/jQuery
A scrollable page can be scrolled to the top using 2 approaches: Method 1: Using window.scrollTo(): The scrollTo() method of the window ...
Read more >
Pull to refresh, page keeps refreshing when I try to scroll to top ...
3) when I did the actual “pull to refresh” action on top. What is your setup? Are you using scrollview or disable scrolling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found