How to trigger a Lightbox with Specific Content from Containers
Product:
Wix Studio Editor
Current Setup:
I have a simple page with three containers. Each container contains a specific image and some text. I have also created a lightbox.
Requirement:
I need each container to trigger the lightbox when clicked. The lightbox should display the same image contained in the clicked container (e.g., clicking on the first container with “Test Image 10” should open the lightbox displaying “Test Image 10”). This functionality should apply to all containers.
How can I achieve this?
What have you already tried:
I have already explored creating a dynamic page, using CMS, and the Wix Pro Gallery. However, these options do not meet my requirements, as I need a custom layout for these containers. I would like to ensure that clicking on the containers does not navigate to another page.
Additional information:
This functionality is similar to the “Expanded View” feature in the Wix Pro Gallery.
import wixWindow from 'wix-window-frontend'
$w('#testImage10').onClick(() => {
// data = whatever data you want to pass to the lightbox
wixWindow.openLightbox('lightboxName', data)
})
Lightbox
import { lightbox } from 'wix-window-frontend'
const data = lightbox.getContext()
That’s how you pass data from a page to a lightbox being opened, you can use this for whatever custom functionality you’d like
@DeanAyalon I do not know coding. I pasted your code in it and it didn’t work, so I asked Wix AI which came up with this and I think it’s similar to yours.
Code for the Page:
Container ID: #sketchbox080
Image ID (inside the container): #image80
Lightbox ID: #Lightbox01
Image ID (inside the lightbox): #lightboximage01 (the image inside the lightbox should change as per which container is clicked)
import { lightbox } from 'wix-window-frontend';
$w.onReady(() => {
// Get the data passed to the lightbox
const receivedData = lightbox.getContext();
// Set the image source in the lightbox
$w('#Lightboximage01').src = receivedData.imageSrc;
});
import { lightbox } from 'wix-window-frontend';
$w.onReady(() => {
// Get the data passed to the lightbox
const receivedData = lightbox.getContext();
// Set the image source in the lightbox
$w('#lightboximagex1').src = receivedData.imageSrc;
});