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?
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:
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.
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?
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.
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.
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.