This Pro tutorial provides the steps to trigger a click on the first image of a gallery in Bricks when a button is clicked.
We are going to set a fixed height for the gallery with
overflow: hidden so that only a few images will be shown and the user can either click on any of the images or on the "View All Photos" button and browse all of them in the lightbox.
Edit your Template/Page with Bricks.
Add a Section.
Add a Image Gallery element inside the Section's container.
Select/upload your desired images or if you have a ACF Gallery field or Meta Box Advanced Image field set up, select it as the source of images.
Link to: Lightbox.
STYLE → LAYOUT: Set a Max. height (534px in my test site).
Add a Button element below the Image Gallery.
Click on the Settings (gear) icon → PAGE SETTINGS → CUSTOM CODE and paste the following under Body (footer) scripts:
This is a BricksLabs Pro tutorial.
For full access login below or create your BricksLabs Pro account
Tried the new code – still not working. But I thank you for writing it; my JS skills are not the best.
Unless I’m misunderstanding what you’re trying to do, it all appears to be working now on your page.. all the gallery buttons are opening up the galleries inside a lightbox.
Hmm – guess I was thrown off by the fact that the pointer didn’t change when I moused over it. Thank you for your help!
Ideally, make it a link or button so it’s clickable / focusable.
On Step 2 – don’t we have to define the “Link” status on the button?
I created, then hid the gallery on Step 1, then created a button and added in the JS code for the page. But the Bricks button is not a button, nor does the JS code define it as such.
The only reason it isn’t working on your page is because you have multiple buttons, all with the same ID. So the JS will only pick up the first one. If using multiple, use the classes instead and use forEach to loop through them..
ie replace step 3 with this..