Shopify themes, liquid, logos, and UX
I have Jumpstart theme on my store
And I want to scroll from the main menu to sections down the same page..
How I do that?
Solved! Go to the solution
This is an accepted solution.
The basic smooth scroll with anchors would work like shown below - since Jumpstart has jQuery I used that for brevity. Also, see my Codepen for a demo.
$(document).ready(function() { $('.smooth-scroll').on('click', function(evt) { evt.preventDefault(); $('html, body').animate( { scrollTop: $($(this).attr('href')).offset().top}, 300 ); }); });
Where you put that in your theme and what elements you decide to smooth scroll is up to you.
Best wishes!
This is an accepted solution.
The basic smooth scroll with anchors would work like shown below - since Jumpstart has jQuery I used that for brevity. Also, see my Codepen for a demo.
$(document).ready(function() { $('.smooth-scroll').on('click', function(evt) { evt.preventDefault(); $('html, body').animate( { scrollTop: $($(this).attr('href')).offset().top}, 300 ); }); });
Where you put that in your theme and what elements you decide to smooth scroll is up to you.
Best wishes!
thats exactly what I need, thank you!
But I have a very basic knowledge in web development
I tried to search there the sections (that I can activate the code on them)
I mean look at the pic I uploaded
where I need to put the code there?
(I tried to search and didnt find my section list items)
Well what exactly you need to change or add and where depends on what sections you want to have the smooth scroll. The main issue I see here is that your main menu is for pages / collections and I am not sure how you envision doing that "scroll to section" from the main menu.
But to begin with, your main menu code can be found in Sections / header.liquid which further includes Snippets / site-nav.liquid and Snippets / drawer-nav.liquid. Your actual section code will be found in a number of Section folder files depending on what section you're looking for. On the index (home) page for instance, the sections you add are wrapped in a <div /> element which is given a unique ID that you can also use for smooth scrolling to it.
I think a step-by-step guide wouldn't be possible without knowing exactly what and where you're trying to add these scroll to's. Even then, I must admit that it would probably not fall in to my scope of "forum advice" but me more suitable for a Shopify Expert to work together with you toward a solution you're happy with. Alternatively, you can try contacting Shopify support directly asking about free theme support which they may be able to provide - and can use my code above to quickly add smooth scroll where you need it.
Best wishes!
thank you for the reply! I really appreciate that!!!
this is the store:
https://8nnolveggqxoeq7l-8257634364.shopifypreview.com
you can see on the bar I have a "features" section, I want that when I click it, it will get me down to this : http://prntscr.com/mjifn2
I finally succeeded thank you so much Karl! im so excited!!
another little thing: It works when i am at the same page, but if im on an FAQ page and try to click that button, it doesnt make anything. How can I make it go to the home page and then smooth scroll(from the FAQ page)
Is it possible?
thanks again Karl You helped me a lot!!
Hi,
On the product detail page, the Features and How it works? menu items do not work because they only link to element IDs that are available on the homepage. Because they do not actually link to the homepage itself, nothing happens.
You have a few options here
Hope this helps!
Hey Karl, Thank you
Hi Karl,
yes 2. is actually what I need, I tried to do:
<li> <a href="www.mypage.com#home-features" class="smooth-scroll">Features</a> </li>
The original code was:
<li> <a href="#home-features" class="smooth-scroll">Features</a> </li>
it didnt work how can I fix it?
Hey Karl! Which file do you put the Javascript snippet into? I am using the Debut theme. Thanks for your help.
Hey Karl,
This code looks great. I have already set up the scroll to section by linking the div/anchor.. Just can't figure out where to insert your code for the smooth scroll.. Can you help out a rookie, please? 🙈
I'm using Debut theme and fixed it by adding one line of CSS snippet.
Add the following snippet at the end of the file: theme.scss.liquid.
(Edit code >> Assets >> theme.scss.liquid)
html {
scroll-behavior: smooth;
}
Yeah, this works like a charm, also on the Dawn theme which I'm using. However, this CSS element is not supported by Safari, so if you're looking to properly serve most customers using iPhones, you'll want to find a different solution, unfortunately.
User | RANK |
---|---|
74 | |
68 | |
60 | |
59 | |
43 |
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023