oli-laban / alpine-tailwind-lightbox

A simple lightbox for AlpineJS and Tailwind CSS projects.
MIT License
2 stars 1 forks source link

Lazy Load when using $lightbox? #5

Closed shaunrobinson closed 1 day ago

shaunrobinson commented 1 week ago

Just checking I haven't missed something obvious - is it possible to lazy load the images when using $lightbox?

If so, how would you change your demo code to do this?

oli-laban commented 3 days ago

@shaunrobinson Yeah this is possible if you pass the images as objects and set lazy: true.

shaunrobinson commented 3 days ago

Can you give me some example code to do this? Thanks!

oli-laban commented 1 day ago

@shaunrobinson Sure, something like:

<div
    x-data="{
        images: [
            { url: 'image-1.jpg', lazy: true },
            { url: 'image-2.jpg', lazy: true },
            { url: 'image-3.jpg', lazy: true },
        ],
    }"
    x-init="$lightbox(images)"
>
    ...
</div>
shaunrobinson commented 1 day ago

Perfect, thanks!