Use the AnimatedGallery component to display a collection of images with animations on hover, creating a dynamic visual experience. They are great for creating immersive, interactive marketing sections on lading pages, and can be used to showcase product images, portfolios, or project highlights.
To create the gallery, pass an array of image objects to the images prop with the following possible properties:
src: Sets the path to the image.
alt: Sets an alternate text for the image.
width and height: Sets the width and height of the image.
lazy: Optionally, set the lazy property to true to lazy-load the image.
Opening Images in Modal
You can use the AnimatedGallery with the Modal component to open images in a modal. To achieve this, create a new and add the following code after importing AnimatedGallery and Modal:
Create your AnimatedGallery component with the className prop to target it later in JavaScript.
Create an empty transparent Modal component.
Create an img variable that can hold reference to the currently selected image.
Create a click event listener for the AnimatedGallery component, and assign the clicked image to the img variable.
When creating the modal instance, specify the onOpen method to run code when the modal is opened. Set the image dimensions to 100% and append it to the modal. Don’t forget to remove previous content by setting innerHTML to an empty string.
Add a click event listener on the opened modal image and call the closeModal method to close the modal when the user clicks on it.
Optionally, you can add some CSS to change the cursor to pointer to indicate to users that the image is interactive.