Shopify themes, liquid, logos, and UX
I have a button in the image with text element, and I'd like it to scroll the user to the top of the page when clicked. I used this code before, but it only worked in the customize section, not on the actual website.
<style>
html {
scroll-behavior: smooth;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
let buttonScrollTop = document.querySelector('.button[data-shopify-editor-block*="button_PfN8Qi"]');
if(buttonScrollTop) {
buttonScrollTop.addEventListener('click', function(e){
e.preventDefault();
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
}
});
Solved! Go to the solution
This is an accepted solution.
Simply add this value in the link of that button
#MainProduct-template--16290336473132__main
- Helpful? Like and Accept solution! Support me: Buy coffee
- Ryviu - Reviews & QA app, collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy app: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Hey @Viajey ,
Welcome to the community!
Can you send over the link and the store password?
♥ If you found my solution helpful, please consider giving it a Like and marking it as the ✔ Accepted Solution
Try our WhatsApp Chat Button Widget with multipe agents.Supachat: WhatsApp Chat Button
A Product of Maverick Studio
For sure. The website is viajey.com and the password is abc123
Hi @Viajey
Maybe you get an element of the editor, so it works only for the editor. Please check on live site and get correct element of button to make it work
- Helpful? Like and Accept solution! Support me: Buy coffee
- Ryviu - Reviews & QA app, collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy app: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
This is what the element is on the live website. How would I add this to my code?
<a role="link" aria-disabled="true" class="button button--primary">
Buy Now
</a>
Could you please show me the code and indicate which section you would like to scroll to when the button is clicked?
- Helpful? Like and Accept solution! Support me: Buy coffee
- Ryviu - Reviews & QA app, collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy app: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
The elements are on this link, and the store password is abc123
https://viajey.com/products/wrap-travel-pillow
The "Buy Now" button in the first image should be clicked to bring the user to the section in the second image.
This is an accepted solution.
Simply add this value in the link of that button
#MainProduct-template--16290336473132__main
- Helpful? Like and Accept solution! Support me: Buy coffee
- Ryviu - Reviews & QA app, collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy app: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
it worked! Thank you!
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024