Create a custom gallery with Elementor

Recently for a client project, we had to create a tailor-made photo gallery, via Elementor, based on our client’s graphic model.

Here is the requested rendering opposite.
When you click on the images below, this will automatically change the large image, almost as if you were in a product sheet with WooCommerce for example.
Natively Elementor does not offer such rendering.

To do this, we have two widgets: Image Widget & for the small images below, the Gallery widget.

We then add in the advanced tab then css classes in the first widget: image-preview and in the second widget we will put the class: img-gallery

All you have to do is inject the code below into Elementor > CustomCode > Add:

				
					<script>
    document.addEventListener('DOMContentLoaded', function() {
        const galleryItems = document.querySelectorAll('.e-gallery-item');
        const previewImage = document.querySelector('.image-preview img');

        galleryItems.forEach(item => {
            item.addEventListener('click', function() {
                const imageUrl = item.querySelector('.e-gallery-image').style.backgroundImage.slice(5, -2);
                previewImage.src = imageUrl;
                previewImage.srcset = imageUrl; // Mettre à jour également srcset
            });
        });
    });
</script>
				
			
Want to leave a comment ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to see more code snippets?

Back to Top for Elementor

“Back to Top” button with progressive fill based on scroll. Automatically uses Elementor's main color.

WooCommerce Gallery Hover for Elementor Loop

Displays the first image in the gallery when hovering over the featured image in Elementor loops.

Free shipping method with WooCommerce coupon

Offer free shipping… but only for the shipping method you choose.

WooCommerce Product Buyers List

Added a tab in WooCommerce to display buyers of a specific product with date filter.

Additional Emails per Products for WooCommerce

Adds a custom tab in WooCommerce products to write an email specific to each product. This will be sent in a dedicated email.

Create a custom gallery with Elementor

With this code we gonna add a custom gallery to an elementor page
Let's talk ?

A question about WordPress?
A web project to be outsourced to a freelancer?
I am your man!