Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
alpine-tailwind-lightbox
Advanced tools
A simple lightbox for AlpineJS and Tailwind CSS projects.
A simple lightbox for AlpineJS and Tailwind CSS projects.
<!-- Lightbox Plugin -->
<script defer src="https://cdn.jsdelivr.net/npm/alpine-tailwind-lightbox@1.x.x/dist/alpine-tailwind-lightbox.min.js"></script>
<!-- Focus Plugin -->
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/focus@3.x.x/dist/cdn.min.js"></script>
<!-- AlpineJS Core -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
Install the package:
npm install alpine-tailwind-lightbox
Then import and initialize the plugin:
import Alpine from 'alpinejs'
import focus from '@alpinejs/focus'
import lightbox from 'alpine-tailwind-lightbox'
Alpine.plugin(focus)
Alpine.plugin(lightbox)
Alpine.start()
Make sure Tailwind can pick up the CSS classes by adding the lightbox HTML to your tailwind.config.js
:
module.exports = {
content: [
// ...
'./node_modules/alpine-tailwind-lightbox/src/template.html',
],
// ...
}
You can create a lightbox by simply passing a URL to the x-lightbox
directive. A click handler will automatically be added to the element with the directive.
<a href="#" x-lightbox="'./image.jpg'">
Open Image
</a>
Note the single quotes around the URL. It is parsed as a JavaScript expression so you can pass Alpine data or an object as below.
For more options, you can pass an object to the lightbox (see the Config Object reference):
<a href="#" x-lightbox="{ url: './image.jpg', alt: 'An image of something' }">
Open Image
</a>
<a href="#" x-lightbox="{ url: './video.mp4', type: 'video' }">
Open Video
</a>
By default, all items will be added to the same "default" lightbox. If you want to create separate lightbox instances on the same page, you can specify a group:
<a href="#" x-lightbox="'./cat.jpg'" x-lightbox:group="cats">
View the Cats
</a>
<a href="#" x-lightbox="'./dog.jpg'" x-lightbox:group="dogs">
View the Dogs
</a>
By default, all images will be fetched in the background on page load. To only fetch an image when it is opened, use the lazy
modifier (or the lazy
config property):
<a href="#" x-lightbox.lazy="'./cat.jpg'" x-lightbox:group="cats">
Open Image
</a>
For smoother navigation between images, when an image is opened this will also load the previous and next image in the lightbox.
It is possible to create a lightbox without needing a DOM element per item. See Magics.
Option | Type | Default | Description |
---|---|---|---|
url | string | The media URL. | |
type | string | image | The media type. image , video or embed . |
group | string? | null | The lightbox group the item should be added to. If omitted, the item is added to the default lightbox. |
lazy | boolean | false | Indicates whether to delay fetching the image until it is opened. Only applies to the image type. |
muted | boolean | false | Determines whether the video should be muted by default. Only applies to the video type. |
autoplay | boolean | false | Determines whether the video should play automatically upon opening the lightbox. Only applies to the video type. |
There are magic functions available for controlling lightboxes programmatically.
$lightbox(items, group)
Parameter | Type | Default | Description |
---|---|---|---|
items | (string|object)[] | An array of URLs or config objects. | |
group | string|null | null | The name of the lightbox group. If null , the items will be added to the default lightbox. |
<div
x-data="{ images: ['./image1.jpg', './image2.jpg', './image3.jpg'] }"
x-init="$lightbox(images)"
></div>
If there are also lightbox items created via
x-lightbox
targeting the same group (default or named), the items will be merged.
$lightbox.open(urlOrRef, group)
Parameter | Type | Default | Description |
---|---|---|---|
urlOrRef | string|HTMLElement|null | null | The URL or element ref of the item to open. If null , the first item in the lightbox will be opened. |
group | string|null | null | The name of the lightbox group. If null , the default lightbox will be opened. |
<img src="#" x-lightbox="'./image.jpg'" x-ref="image" alt="Example image">
<a href="#" @click="$lightbox.open('./image.jpg')">Open Image</a>
or
<a href="#" @click="$lightbox.open($refs.image)">Open Image</a>
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
A simple lightbox for AlpineJS and Tailwind CSS projects.
The npm package alpine-tailwind-lightbox receives a total of 2 weekly downloads. As such, alpine-tailwind-lightbox popularity was classified as not popular.
We found that alpine-tailwind-lightbox demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.