Return to same scroll position in dawn theme

Return to same scroll position in dawn theme

oudelegance
Visitor
2 0 1

Anyone knows how to return to the same scroll position in dawn theme? I saw a fix for turbo theme which didn't apply for dawn. 

Replies 5 (5)

kirillatwally
Excursionist
37 1 5

Hi @oudelegance 

 

Add this script to your theme.liquid file or base.js:

 

window.addEventListener("beforeunload", () => {
  sessionStorage.setItem("scrollPosition", window.scrollY);
});

window.addEventListener("load", () => {
  const scrollPosition = sessionStorage.getItem("scrollPosition");
  if (scrollPosition) {
    window.scrollTo(0, scrollPosition);
  }
});

 

 

How it works:

  1. When you leave the page, the scroll position is saved in sessionStorage.
  2. When you return to the page, the scroll position is restored.
Kirill at Wally Reviews

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution

Judithharrison
Shopify Partner
1 0 1

Hi @oudelegance I was facing the same issue, and the code shared by @kirillatwally  worked perfectly for me. You should give it a try.
Thank you 😊😊😊😊😊😊😊😊😊

Dtf Film
dtf film

DaisyVo
Shopify Partner
2299 282 328

Hi @oudelegance 

 

I hope you are well. You can follow our instructions below:


Step 1: Shopify admin > Online store > Edit code: https://prnt.sc/M4p-gua99Uf4
Step 2: Search for "theme.liquid" file: https://prnt.sc/b6xveIKe-Rh2
Step 3: Open the file search for </body> tag and add the following code above </body> tag.

 

<script>
window.addEventListener("beforeunload", () => {
  sessionStorage.setItem("scrollPosition", window.scrollY);
});
window.addEventListener("load", () => {
  const scrollPosition = sessionStorage.getItem("scrollPosition");
  if (scrollPosition) {
    window.scrollTo(0, scrollPosition);
  }
});
</script>

 

Here is the code for Step 3:

 


Please let me know if it works. Thank you!

 

Best,
Daisy - Avada Support Team.

Please let us know if our reply is helpful by giving it a Like or marking it as a Solution!

Avada SEO & Image Optimizer - The #1 SEO solution
oudelegance
Visitor
2 0 1

Hi, thank you for your response. 
I couldn't search for </body> it doesn't exist like that in theme.liquid. 
So I pasted it here (see screenshot). Now does it need to be indented. This did not work for me. By the way, I am having this issue on mobile phone. When you click on a product from one of the collections, then click back, it takes you to the top of the homepage, not where you clicked on the product in the first place. 

oudelegance_0-1735025251670.png

 

DaisyVo
Shopify Partner
2299 282 328

Hi @oudelegance 

 

From the screenshot you shared, could you please scroll down to the bottom to find </body tag? 

 

Best,
Daisy - Avada Support Team.

Please let us know if our reply is helpful by giving it a Like or marking it as a Solution!

Avada SEO & Image Optimizer - The #1 SEO solution