Shopify themes, liquid, logos, and UX
This issue only apply to Dawn theme > mobile device.
Scenario: User is on product page and scroll down until they see variant options such as size / color.
Whenever a product variant is selected (either dropdown or pill format), page is scrolled back to the top automatically which is a bad user experience. Spent the last a few hours and couldn't figure out how to disable auto scroll.
Has anyone experience similar issue and has a solution?
Here is example product page
Any help is greatly appreciated. Thanks
this this code
$(document).ready(function(){
$('select, input[type="radio"]').on('change', function() {
var currentPos = $(window).scrollTop();
$('html, body').scrollTop(currentPos);
});
});
This code should prevent the page from scrolling to the top by saving the current scroll position and restoring it after the variant is selected.
If this fixed your issue, likes and accepting as a solution are highly appreciated
| Build an online presence with our custom-built Shopify Theme: EcomifyTheme
| Check out our reviews: Trustpilot Reviews
| We are Shopify Partners: EcomGraduates Shopify Partner
Thank you so much for your solution which works 👍.
We also found another solution which is commenting out JS line item from media-gallery.js.
I was having the same issue as OP and this did the trick. Thank you!
Works perfect man 🙂 thanks
So I use Dawn version 13.0.1, but I can not find this text in the media-gallery asset folder. Any one a solution please?
thanks man
Logged in especially to say thank you for this
Where do you paste this code and does it work for the Studio Theme as well. Also does this work for the size of a product as well?
I am having the same issue. Where are you placing this code?
Disclaimer: You understand the risks in modifying your code and either are able to undo these changes or have saved your code before making modification. DO NOT attempt if you don't feel confident in modifying your Shopify Theme code. I am not responsible for your mess 😉
If you have not solved this by now, go to Online Store / Themes, click the 3 dots/menu button of your current theme, then Edit Code.
On the new page, on the left hand side, type "media-gallery.js" (without the quotes) in the search box.
Click the media-gallery.js file.
On your keyboard, hit CTRL+F to search the file for "if (!this.elements.thumbnails || this.dataset.desktopLayout === 'stacked') {". On my file, it is at line 46 but it could be different for you theme.
Once you have located this code, look at the line underneath it. You should see this:
activeMedia.scrollIntoView({behavior: 'smooth'});
Add // in front of the word active.
It should now look like this:
//activeMedia.scrollIntoView({behavior: 'smooth'});
Hit the Save button (top right of the page).
This is the easiest way to manage what the OP tried to accomplish.
Hope this helps.
THIS IS THE BEST!!!!! IT WORKS!!!
THANK YOU THANK YOU THANK YOU!!!
This was such an easy fix! Thank you.
Hello,
I am having the same issue in the sense theme and ctrl+f does not show an "if (!this.elements.thumbnails || this.dataset.desktopLayout === 'stacked') {" in "media-gallery.js"
Could the code be something else in this newer version?
Thanks
Hey!
First of all I am just building my website and have worked so many hours on that problem...
I saw your response and THANK YOU!!!
I just have something to add in favor of future people with the same problem but with a different theme than Dawn.
So I am using Spotlight Theme and it's very good-looking but I find myself need to add many customizations in the code myself that don't exist in the basic theme.
Anyhow, I saw your post and for me the line "if (!this.elements.thumbnails || this.dataset.desktopLayout === 'stacked') {" doesn't exists, so I entered media-gallery.js file like you and searched (with CTRL + F) for "behavior:" (without the quotes).
It then occurred to me that there was only one line which is: "window.scrollTo({ top: top, behavior: 'smooth' });". For me it was at line 63.
So I added the comment "//" in the beginning of this line and it worked like a charm!!!
I can't believe how many hours I spent on this... minimum of 5...
So if anyone in the future sees this and use spotlight theme (or any other theme) just look for "behavior:" and you'll find it.
Hope I'll help someone 🙂
--
Eyal
This works! Wish I'd looked sooner. Thank you so much.
Not to be greedy, but is there a way to keep te scrolling for the color variant buttons, but not the size variant buttons? It seems like when you choose another color, it should scroll up to show you, but when you choose a size, it should not.
If anyone is using DAWN THEME you can do this same method, but the code you need to locate will look like this:
window.scrollTo({ top: top, behavior: 'smooth' });
I'm using the Shopify Enterprise theme and can't find activeMedia.scrollIntoView({behavior: 'smooth'}); within media-gallery.js. Would I need to do something different?
Thank you!!
Where do you put this code?
Hi! I am having this same issue. Where do I add this code?
For me commenting out the code did solve the scroll issue but on mobile it didn't switch the variant image anymore, so I had to add one more line of code to manualy scroll to the 1st image in the slider when variant changes. I wrote a post about it.
Hello, this doesnt work on the dawn theme version 13. Could you please have a look at this version? Thanks
Hi all, sorry for the late reply, the code changed a little with the newer versions of the Dawn theme, now you just need to comment out a few lines. I've updated the post to include the change for the newer version look at my post here.
hey did you figure out how to fix it now on the new theme? Im using Sense 15.0.0 i guess its the same as Dawn 15.0.0
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024