We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

button motion when pressed

button motion when pressed

shop22dash
Excursionist
22 0 4

i want so when i press this button it takes the user down in a quick motion to the cta dynamic button

Replies 2 (2)

swym
Trailblazer
217 46 94

Hello @shop22dash!

 

We can easily solve this issue by using a simple event listener and the scrollTo() method. Please refer to the steps below to achieve this end-to-end. 

 

1. Open the Code Editor for the theme where you would like to apply the modifications as directed in the screenshot below. 

 

swym_0-1749730688788.png

 

2. Let’s create a new snippet to add these modifications. We suggest using a snippet so you can easily add or remove it as needed. The screenshot below shows how to create a new snippet.

swym_1-1749730714846.png

 

3. Now, inside this file, paste in the code below: 

<script>
  const redirectButton = document.getElementById('redirect-button-id');
  const targetButton = document.getElementById('target-button-id');
  const targetButtonTop = targetButton.offsetTop;
  
  redirectButton.addEventListener("click",()=>{
    window.scrollTo({top: targetButtonTop, behavior: 'smooth'})
  })
</script>

 

Note: You would need to update the ids, or selectors for your store’s buttons/elements. In the example code shared above, the targetButton is the element I am taking the user to when the redirectButton is clicked.

 

4. Finally, let's render this file inside your theme layout file just before the closing </body> tag. Screenshot below for reference.

swym_2-1749730767622.png

 

Once saved, let’s go to the storefront. This is what it should now behave like:

 

swym_3-1749730795648.gif

 

If my response helped you, please consider giving it a like (👍) and marking it as an accepted solution if it resolved your issue. Your feedback helps other community members with similar questions. 

 

Thank you!

 

Regards, 

Aaryan from Swym

 

 

- Appreciate the assistance. Show your approval with a Like! And when your question finds its answer, seal the deal by marking it as an Accepted Solution!
- Our Solutions: Wishlist Plus | Swym Back in Stock Alerts | Swym Gift Lists and Registries
kaalTechGeeks
Shopify Partner
319 58 81

Hey @shop22dash 

What @swym gave is actually a really good solution. Once you add this it should implement the button. 

 

Let me know if I can help you in any way. 

 

Best, 

KaalTechGeeks 

- If my answers saved you time and headaches, consider buying me a coffee!
- Check my profile: KaalTechGeeks | Reach out to me on my socials - Instagram | Skype | Mail
- Was my reply helpful? Click Like to let me know! & if your question was answered, Mark it as an Accepted Solution!