Confetti Effect When Submitting a Divi Contact Form

Easy

Javascript

Details

Are you looking to add a captivating touch to celebrate every time a user submits your Divi Contact Form module? Well, we’ve got just the thing for you!

This Divi Code snippet elevates the user experience by introducing a confetti effect to the submission of your Divi Contact Form module. Upon clicking the submit button, some vibrant confetti particles burst onto the screen, crafting an exhilarating visual spectacle. This infusion of excitement and interaction enhances the form submission process on any website built with the Divi theme.

Snippets Demo

Demo of Confetti Effect when Submitting a Divi Contact Form

Code

1

Description:
This code loads the confetti.browser.js library.

Language: Javascript

Where to add: Divi Code Module

                        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.js"></script>
                    
2

Description:
This code first adds a .confetti-button class to the submit button of the Divi Contact Form Module using Javascript and then listens for a click on the Submit Button. When a click is detected, it then uses the library we loaded to show the confetti when clicked.

Language: Javascript

Where to add: Divi Theme Options

                        <script>
// Event listener for when the DOM (Document Object Model) is fully loaded.
document.addEventListener('DOMContentLoaded', function() {

    // Selects the first submit button within the Divi Contact Form module.
    var submitButton = document.querySelector('.et_pb_contact_submit');

    // Checks if the submit button exists to prevent errors if the button is not found.
    if (submitButton) {
        // Adds a new class 'confetti-button' to the submit button for later reference.
        submitButton.classList.add('confetti-button');
    }

    // Selects the button with the class 'confetti-button'.
    const confettiButton = document.querySelector('.confetti-button');

    // Checks if the confetti button exists to avoid errors.
    if (confettiButton) {
        // Attaches an event listener for a 'click' event on the confetti button.
        confettiButton.addEventListener('click', function(event) {
            // Gets the position and dimensions of the confetti button.
            const rect = confettiButton.getBoundingClientRect();

            // Calculates the horizontal (x) and vertical (y) center points of the button.
            const x = (rect.left + rect.right) / 2;
            const y = (rect.top + rect.bottom) / 2;

            // Defines settings for the confetti effect.
            const confettiSettings = {
                particleCount: 100, // Number of confetti particles.
                spread: 70,        // Spread angle of the confetti.
                // Sets the origin point for the confetti effect based on button's position.
                origin: { x: x / window.innerWidth, y: y / window.innerHeight }
            };

            // Triggers the confetti effect with the defined settings.
            confetti(confettiSettings);
        });
    }
});
</script>
                    

Related Snippets

Explore more from Divi Engine

Divi Form Builder

Divi Form Builder

From simple contact forms to complex frontend post or product creation, Divi Form Builder has you covered.

Divi Form Builder
Find out more
Divi Machine

Divi Machine

Build complex websites that displays dynamic fields you can filter, search and so much more with the Divi Builder.      

Divi Machine
Find out more
Divi BodyCommerce

Divi BodyCommerce

A versatile toolkit for developers using Divi and WooCommerce together, designed to boost your e-commerce site and achieve greater conversion rates.    

Divi BodyCommerce
Find out more
Divi Handoff

Divi Handoff

Let clients update content without touching the Divi Builder. Design layouts once, connect them to Flexible Content fields, and give editors simple forms for text, images, and sections.

Divi Handoff
Find out more
Divi Loop Extender

Divi Loop Extender

Unlock the Full Power of Divi 5 Loop Builder Add advanced sorting, filtering, and relationship logic right inside the Visual Builder.

Divi Loop Extender
Find out more
Divi Membership

Divi Membership

Monetize your Divi websites by transforming them into membership sites with seamless subscription management, user-friendly interfaces, and customizable membership tiers.

Divi Membership
Find out more
Divi Machine Accounts

Divi Machine Accounts

Build an account area for your customers to edit their details, access wishlist, submitted posts and more. *Note: Requires Divi Machine installed and active

Divi Machine Accounts
Find out more
Divi Ajax Filter

Divi Ajax Filter

Filter WooCommerce, Posts & Custom Posts without reloading the page.    

Divi Ajax Filter
Find out more
Divi Mobile

Divi Mobile

Divi Mobile helps you create beautiful looking mobile menus without having to code.

Divi Mobile
Find out more
Divi Nitro

Divi Nitro

Give your Divi website that extra boost of speed with our Divi Nitro plugin to enhance your customer's experience.

Divi Nitro
Find out more
Divi Protect

Divi Protect

Password protect the content of your Divi website with our Divi Protect plugin. Keep unwanted eyes out!

Divi Protect
Find out more
Divi Mega Menu

Divi Mega Menu

Create stunning, responsive, and content-rich mega menus using the Divi Builder you already know. No coding required.  

Divi Mega Menu
Find out more