Hot Line:

+1 (917) 730-2010

AI-Powered Web Development, SEO, Shopify & WordPress — Get a Free Consultation Today. Get Started

Tutorials

How To Make A Confetti Effect on Add to Cart Button in Shopify

  • 07 Nov, 2024
  • 0 Comments
  • By WebSensePro
How To Make A Confetti Effect on Add to Cart Button in Shopify

Step 1: Add the below line of code in “Theme.liquid”

Add the following code:

<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.6.0/dist/confetti.browser.min.js"></script>

Step 2: Add the below code in snippets “buy-buttons.liquid”file

Just before the following code </product-form>, add the below code:

        <script>
          document.addEventListener('DOMContentLoaded', function() {
            const addToCartButton = document.querySelector('#ProductSubmitButton-{{ section_id }}');
            if (addToCartButton) {
              addToCartButton.addEventListener('click', function() {
                 confetti({
                  particleCount: 200, // Number of confetti particles
                  spread: 100,         // Spread of the confetti
                  origin: { y: 0.8, x: 0.8 } // Confetti origin point, 0 is the top, 1 is the bottom
        });
              });
            }
          });
        </script>
5/5 · 7 votes
Tags:

    Comments

    Background Pattern

    Want to work with us?

    Let’s build your website, grow your traffic, and automate your business with AI.

    Background Pattern