- Notifications
You must be signed in to change notification settings - Fork194
Lightweight, accessible and responsive lightbox.
License
jsor/lity
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Lity is a ultra-lightweight, accessible and responsive lightbox plugin whichsupports images, iframes and inline content out of the box.
Minified and gzipped, its total footprint weights about 3kB.
It requiresjQuery orZepto(with thecallbacks,data,deferred andevent modules).
All ready-to-use files are located in thedist/
directory.
Include the Lity javascript and css files and its dependencies in your HTMLdocument:
<linkhref="dist/lity.css"rel="stylesheet"><scriptsrc="vendor/jquery.js"></script><scriptsrc="dist/lity.js"></script>
Lity can also be installed via Bower ornpm.
Add thedata-lity
attribute to<a>
elements for which you want the links tobe opened in a lightbox:
<ahref="https://farm9.staticflickr.com/8642/16455005578_0fdfc6c3da_b.jpg"data-lity>Image</a><ahref="#inline"data-lity>Inline</a><ahref="https://www.youtube.com/watch?v=XSGBVzeBUbk"data-lity>iFrame Youtube</a><ahref="https://vimeo.com/1084537"data-lity>iFrame Vimeo</a><ahref="https://maps.google.com/maps?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA"data-lity>Google Maps</a><divid="inline"style="background:#fff"class="lity-hide"> Inline content</div>
If you want to open another URI than defined in thehref
attribute, just addadata-lity-target
with the URI:
<ahref="/image.html"data-litydata-lity-target="/image-preview.jpg">Image</a>
Thelity
function can be either used directly to open URLs (or HTML) in alightbox or as an event handler.
Lity lity(string target, [Object options, [, HTMLElement|$ opener]])
target
: The URL or HTML to open.options
: Options as an object of key-value pairs.opener
: The element which triggered opening the lightbox (if used as a eventhandler, this is automatically set to the element which triggered the event).
ALity
instance.
// Open a URL or HTML in a lightboxlity('https://www.youtube.com/watch?v=XSGBVzeBUbk');lity('<p>Some content to show...</p>');// Bind as an event handler$(document).on('click','[data-my-lightbox]',lity);
If you open a lightbox programmatically, thelity
function returns aLity
instance you can use to interact with the lightbox.
TheLity
instance is also passed as the second argument to theevent handlers.
varinstance=lity('https://www.youtube.com/watch?v=XSGBVzeBUbk');
Closes the lightbox and returns a promise which resolves once the closinganimation is finished.
instance.close().then(function(){console.log('Lightbox closed');});
Returns the root HTML element.
varelement=instance.element();
Returns the HTML element which triggered opening the lightbox.
varopener=instance.opener();
Note: The value might be undefined if the lightbox has been openedprogrammatically and not by a click event handler and no opener argument wasprovided.
Returns the content HTML element.
varcontent=instance.content();
Note: The value is undefined while the content is loading.
Sets or returns options of the instance.
varallOptions=instance.options();vartemplate=instance.options('template');instance.options('template','<div>...</div>');varcloseOnEsc=instance.options('esc');instance.options('esc',false);
All events receive theLity
instance as the secondargument.
Triggered before the lightbox is opened.
$(document).on('lity:open',function(event,instance){console.log('Lightbox opened');});
Triggered when the lightbox is ready.
$(document).on('lity:ready',function(event,instance){console.log('Lightbox ready');});
Triggered before the lightbox is closed.
$(document).on('lity:close',function(event,instance){console.log('Lightbox closed');});
Triggered when the closing animation is finished and just before the lightboxis removed from the DOM.
$(document).on('lity:remove',function(event,instance){console.log('Lightbox removed');});
Triggered when the instance is resized, usually when the user resizes thewindow.
$(document).on('lity:resize',function(event,instance){console.log('Lightbox resized');});
Copyright (c) 2015-2020 Jan Sorgalla.Released under theMIT license.
About
Lightweight, accessible and responsive lightbox.