Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use lightGallery for jQuery? #1586

Open
kukrik opened this issue Jan 18, 2024 · 3 comments
Open

Is it possible to use lightGallery for jQuery? #1586

kukrik opened this issue Jan 18, 2024 · 3 comments

Comments

@kukrik
Copy link

kukrik commented Jan 18, 2024

Hello, dear folks!

I might have a silly question?! Unfortunately, I am still using another framework that expects minimal interaction with jQuery. I'm gradually transitioning to full JavaScript. If I create my JavaScript plugin for my framework, I'll wrap it in a jQuery wrapper so that it can still communicate with the framework.

I really like the JavaScript lightGallery, let it stay that way! Here's a quick question: can it be wrapped with a jQuery wrapper? For example, I would like to do something like $("#lightgallery").lightGallery(); or $("#lightgallery").lightGallery({options}); No need to think further :)!

I apologize in advance if my question is off-topic.

Thanks in advance!

@bytesandbots3
Copy link
Contributor

bytesandbots3 commented Feb 15, 2024

@kukrik , Regarding your question lightGallery is a standalone JavaScript library and does not have a built-in jQuery wrapper. It is designed to be used directly with JavaScript. However, if you want to use LG with jQuery, you can create a custom jQuery plugin that wraps the lightGallery functionality. This way, you can use jQuery syntax to initialize and interact with lightGallery.

Here's an example of how you can create a custom jQuery plugin for LG:

        (function ($) {
            $.fn.lightGallery = function (options) {
                this.each(function () {
                    lightGallery(this, options);
                });
                return this;
            };
        })(jQuery);

        $('#animated-thumbnails-gallery').lightGallery({
            pager: false,
            hash: false,
            mode: 'lg-zoom-in-out',
            selector: '.gallery-item',
            addClass: 'lightGallery-white-theme',
            plugins: [
                lgZoom,
                lgAutoplay,
                lgFullscreen,
                lgPager,
                lgRotate,
                lgShare,
                lgThumbnail,
                lgVideo,
            ],
            mobileSettings: {
                controls: false,
                showCloseIcon: false,
                download: false,
                rotate: false,
            },
        });

With this custom jQuery plugin, you can now use
$("#lightgallery").lightGallery(); or $("#lightgallery").lightGallery({options});
to initialize lightGallery and pass any options you want.

I hope this helps!

Copy link

stale bot commented Apr 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the v1 label Apr 16, 2024
@kukrik
Copy link
Author

kukrik commented Apr 16, 2024

Thanks! I saved this suggestion to my computer. I have a few projects to finish. If necessary, I can reopen this ticket!

Thanks again!

@stale stale bot removed the v1 label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants