AttRibutes
Smart Lightbox
What is this page about?

Attributes, by Finsweet, offers a free series of Solutions that provide essential features to improve your Webflow websites.

Smart Lightbox

Change the position of an opened lightbox to prevent unwanted z-index, fixed positioning, and transform issues.

Smart Lightbox • Flash Card

Copy Script

For advanced users familiar with this solution. Includes all attributes from this page. Click on attributes and values to copy them.

Required attributes

Lightbox

Add to Div Block, Lighbox Element

fs-smartlightbox-element
=
"
lightbox
"

Trigger Open

Add to Button, Text Link, Link Block, Div Block

fs-smartlightbox-element
=
"
trigger-open
"

Trigger Close

Add to Button, Text Link, Link Block, Div Block

fs-smartlightbox-element
=
"
trigger-close
"

Trigger Toggle Open/Close

Add to Button, Text Link, Link Block, Div Block

fs-smartlightbox-element
=
"
trigger-open
"

Optional attributes

Wait to cloe

Add to Trigger (Open, Cloe, Toggle)

fs-smartlightbox-wait
=
"
TIME_IN_MS
"
1

Add this <script> inside the <head> tag of your page or project

This script is the universal Attribute script: you only need to include it once, even if you have multiple Attribute solutions on the page. Learn more .

<script async type="module"
src="https://cdn.jsdelivr.net/npm/@finsweet/attributes@2/attributes.js"
fs-smartlightbox
></script>

Copy Script
2

Add these required attributes to the elements

Lightbox

Target the Lightbox Element
fs-smartlightbox-element
=
"
lightbox
"

This attribute should be placed on the outermost parent of the lightbox, popup, or modal element. It controls the element's position within the Document Object Model (DOM) as it is opened and closed.

  • When the lightbox is opened, it becomes a direct child of the Body element. This adjustment circumvents any issues related to z-index, fixed positioning, and transformations.
  • Once the lightbox is closed, it reverts to its original location on the page.
Add this attribute:
Name
fs-smartlightbox-element
Copy
Value
lightbox
Copy
Add it to those type(s) of element(s):
Liightbox
Div Block

Trigger Open

Opening trigger
fs-smartlightbox-element
=
"
trigger-open
"

Apply this attribute to an "Open" button to enable Smart Lightbox functionality, altering the lightbox's position in the Document Object Model (DOM) upon clicking.

Note: This attribute alone does not trigger the lightbox to open. Utilize Webflow Interactions to execute the lightbox's opening action.

Add this attribute:
Name
fs-smartlightbox-element
Copy
Value
trigger-open
Copy
Add it to those type(s) of element(s):
Div Block
Link Block
Link
Button

Trigger Close

Closing trigger
fs-smartlightbox-element
=
"
trigger-close
"

This attribute should be attached to an "X" or "Close" button to disable the Smart Lightbox functionality, ensuring the lightbox returns to its original position in the Document Object Model (DOM) when clicked.

Add this attribute:
Name
fs-smartlightbox-element
Copy
Value
trigger-close
Copy
Add it to those type(s) of element(s):
Div Block
Link Block
Link
Button
IMPORTANT

The attribute itself does not close the lightbox. To actually close the lightbox, you need to use Webflow Interactions.

3

Publish your project! Done, easy right?

Check more elements and settings below
Optional

Add more

elements

Trigger Toggle Open/Close

Toggle trigger
fs-smartlightbox-element
=
"
trigger-toggle
"

This attribute should be used on a button that serves to both open and close the lightbox, toggling the Smart Lightbox functionality. When activated, it modifies the lightbox's position within the Document Object Model (DOM).

Add this attribute:
Name
fs-smartlightbox-element
Copy
Value
trigger-toggle
Copy
Add it to those type(s) of element(s):
Div Block
Link Block
Link
Button
IMPORTANT

This attribute does not open/close the lightbox. Use Webflow Interactions to perform the action of opening/closing the lightbox.

Optional

Add more

settings

Wait to close

Delay the Smart functionality
fs-smartlightbox-wait
=
"
TIME_IN_MS
"

This option introduces a delay to the Smart Lightbox functionality upon closing the lightbox, allowing time for a Webflow Interaction to complete.

Ensure the value is specified in milliseconds and entered without the "ms" suffix, like "250".

Add this attribute:
Name
fs-smartlightbox-wait
Copy
Value
TIME_IN_MS
Copy
Example:
fs-smartlightbox-wait = "450"
Add it to any element with
fs-smartlightbox-element = "trigger-open"
fs-smartlightbox-element = "trigger-close"
fs-smartlightbox-element = "trigger-toggle"
EXAMPLE

For instance, if the closing animation of the lightbox in Webflow Interactions lasts 400 milliseconds, you can set TIME_IN_MS to "400".

Still need help?