Shopify themes, liquid, logos, and UX
Hello guys,
I have a problem with auto scroll top on mobile. When I back from product/page I am immediately sent to the top. Very unpleasant experience. In previous discussions I found the following code:
<main id="MainContent" class="content-for-layout focus-none" role="main" tabindex="-1">
{{ content_for_layout }}
</main>
It said to delete lines 1 and 3 and it would work. The real ones were working, but today I noticed that everything is back.
Password: amber
Thank you so much!
Solved! Go to the solution
This is an accepted solution.
Hello @Atsimataves, to do that, you can find the theme.liquid file and add the following code:
<script> if (window.location.pathname === '/') { if (localStorage.getItem("my_app_name_here-quote-scroll") != null) { const savedScrollPosition = localStorage.getItem("my_app_name_here-quote-scroll"); window.scrollTo(0, savedScrollPosition); } window.onscroll = function() { localStorage.setItem("my_app_name_here-quote-scroll", window.scrollY); }; } </script>
This code will save the location of the page before being routed to another page into localStorage. Then when you return to the page, the website will take the location saved in localStorage and move to that location. Hope this can help you.
If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here ☕.
B2B Solution & Custom Pricing | Product Labels by BSS
Need help from our expert? Kindly share your request with us via community@bsscommerce.com
This is an accepted solution.
Hello @Atsimataves, to do that, you can find the theme.liquid file and add the following code:
<script> if (window.location.pathname === '/') { if (localStorage.getItem("my_app_name_here-quote-scroll") != null) { const savedScrollPosition = localStorage.getItem("my_app_name_here-quote-scroll"); window.scrollTo(0, savedScrollPosition); } window.onscroll = function() { localStorage.setItem("my_app_name_here-quote-scroll", window.scrollY); }; } </script>
This code will save the location of the page before being routed to another page into localStorage. Then when you return to the page, the website will take the location saved in localStorage and move to that location. Hope this can help you.
If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here ☕.
B2B Solution & Custom Pricing | Product Labels by BSS
Need help from our expert? Kindly share your request with us via community@bsscommerce.com
@BSS-Commerce Mystical, but for now my method written before works. Anyway, I saved this code in a draft and will definitely use it!
Thank you very much for your time and help. 💛
Hi, I tried this and it didn’t work unfortunately, can you help me please I am having the same problem? When browsing products on my website through a link on Instagram and you click the back button it takes you back to the top of the page.
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024