Animated Gallery
Display a list of images with animations
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
andheight
: Sets the width and height of the image.lazy
: Optionally set thelazy
property totrue
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 theclassName
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 theAnimatedGallery
component, and assign the clicked image to theimg
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 settinginnerHTML
to an empty string. - Add a
click
event listener on the opened modal image and call thecloseModal
method to close the modal when the user clicks on it. - Optionally, you can add some CSS to change the
cursor
topointer
to indicate to users that the image is interactive.
API
Prop | Purpose |
---|---|
images | Sets the images for the gallery. |
images.src | Sets the path for the image. |
images.alt | Sets an alternate text for the image. |
images.width | Sets the width of the image. |
images.height | Sets the height of the image. |
images.lazy | Set to true to enable lazy loading for the image. |
className | Pass additional CSS classes for the AnimatedGallery component. |
Request improvement for this page