All Projects → jsor → Lity

jsor / Lity

Licence: mit
Lightweight, accessible and responsive lightbox.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lity

react-gallery-carousel
Mobile-friendly gallery carousel 🎠 with server side rendering, lazy loading, fullscreen, thumbnails, touch, mouse emulation, RTL, keyboard navigation and customisations.
Stars: ✭ 178 (-83.06%)
Mutual labels:  responsive, accessibility, modal, lightbox
Magnify
🖼 A jQuery plugin to view images just like in Windows. Browser support IE7+!
Stars: ✭ 177 (-83.16%)
Mutual labels:  modal, lightbox, responsive
Photoviewer
🌀 A JS plugin to view images just like in Windows.
Stars: ✭ 203 (-80.69%)
Mutual labels:  modal, lightbox, responsive
Baguettebox.js
⚡ Simple and easy to use lightbox script written in pure JavaScript
Stars: ✭ 2,252 (+114.27%)
Mutual labels:  modal, lightbox, responsive
fancybox
jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.
Stars: ✭ 7,261 (+590.87%)
Mutual labels:  responsive, modal, lightbox
Air Light
WordPress starter theme - designed to be minimal, lightweight and easy for all kinds of WordPress projects. Public Roadmap: https://favro.com/organization/3b45e73eaf083f68fefef368/c1dd2d4a99d6723904d2e763
Stars: ✭ 285 (-72.88%)
Mutual labels:  lightweight, accessible
Basiclightbox
The lightest lightbox ever made.
Stars: ✭ 299 (-71.55%)
Mutual labels:  modal, lightbox
Lightcase
The smart and flexible Lightbox Plugin.
Stars: ✭ 413 (-60.7%)
Mutual labels:  modal, lightbox
React Cool Portal
😎 🍒 React hook for Portals, which renders modals, dropdowns, tooltips etc. to <body> or else.
Stars: ✭ 458 (-56.42%)
Mutual labels:  modal, lightbox
Parvus
An accessible, open-source image lightbox with no dependencies.
Stars: ✭ 248 (-76.4%)
Mutual labels:  accessibility, lightbox
Ngx Gallery
Angular Gallery, Carousel and Lightbox
Stars: ✭ 417 (-60.32%)
Mutual labels:  modal, lightbox
Adapt framework
A toolkit for creating responsive, accessible, multilanguage HTML5 e-learning courses.
Stars: ✭ 473 (-55%)
Mutual labels:  accessibility, responsive
Body Scroll Lock
Body scroll locking that just works with everything 😏
Stars: ✭ 3,357 (+219.41%)
Mutual labels:  modal, lightbox
Accessible Image Lazy Load
😴 gandul! accessible lazy loading images
Stars: ✭ 281 (-73.26%)
Mutual labels:  accessibility, accessible
Optikey
OptiKey - Full computer control and speech with your eyes
Stars: ✭ 3,906 (+271.65%)
Mutual labels:  accessibility, accessible
react-micro-modal
Accessible, lightweight and configurable modal component with a11y-enabled.
Stars: ✭ 36 (-96.57%)
Mutual labels:  accessibility, modal
React Responsive Modal
Simple responsive react modal
Stars: ✭ 429 (-59.18%)
Mutual labels:  modal, responsive
Mediumlightbox
Nice and elegant way to add zooming functionality for images, inspired by medium.com
Stars: ✭ 671 (-36.16%)
Mutual labels:  modal, lightbox
React Accessible Accordion
Accessible Accordion component for React
Stars: ✭ 610 (-41.96%)
Mutual labels:  accessibility, accessible
React Useportal
🌀 React hook for Portals
Stars: ✭ 698 (-33.59%)
Mutual labels:  modal, lightbox

Lity

Lity is a ultra-lightweight, accessible and responsive lightbox plugin which supports images, iframes and inline content out of the box.

Minified and gzipped, its total footprint weights about 3kB.

It requires jQuery or Zepto (with the callbacks, data, deferred and event modules).

Installation

All ready-to-use files are located in the dist/ directory.

Include the Lity javascript and css files and its dependencies in your HTML document:

<link href="dist/lity.css" rel="stylesheet">
<script src="vendor/jquery.js"></script>
<script src="dist/lity.js"></script>

Lity can also be installed via Bower or npm.

Usage

Declarative

Add the data-lity attribute to <a> elements for which you want the links to be opened in a lightbox:

<a href="https://farm9.staticflickr.com/8642/16455005578_0fdfc6c3da_b.jpg" data-lity>Image</a>
<a href="#inline" data-lity>Inline</a>
<a href="https://www.youtube.com/watch?v=XSGBVzeBUbk" data-lity>iFrame Youtube</a>
<a href="https://vimeo.com/1084537" data-lity>iFrame Vimeo</a>
<a href="https://maps.google.com/maps?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA" data-lity>Google Maps</a>

<div id="inline" style="background:#fff" class="lity-hide">
    Inline content
</div>

If you want to open another URI than defined in the href attribute, just add a data-lity-target with the URI:

<a href="/image.html" data-lity data-lity-target="/image-preview.jpg">Image</a>

Programmatic

The lity function can be either used directly to open URLs (or HTML) in a lightbox or as an event handler.

Lity lity(string target, [Object options, [, HTMLElement|$ opener]])

Arguments

  • 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 event handler, this is automatically set to the element which triggered the event).

Return value

A Lity instance.

Example

// Open a URL or HTML in a lightbox
lity('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);

The Lity instance

If you open a lightbox programmatically, the lity function returns a Lity instance you can use to interact with the lightbox.

The Lity instance is also passed as the second argument to the event handlers.

var instance = lity('https://www.youtube.com/watch?v=XSGBVzeBUbk');

API

Lity.close

Closes the lightbox and returns a promise which resolves once the closing animation is finished.

instance.close().then(function() {
    console.log('Lightbox closed');
});

Lity.element

Returns the root HTML element.

var element = instance.element();

Lity.opener

Returns the HTML element which triggered opening the lightbox.

var opener = instance.opener();

Note: The value might be undefined if the lightbox has been opened programmatically and not by a click event handler and no opener argument was provided.

Lity.content

Returns the content HTML element.

var content = instance.content();

Note: The value is undefined while the content is loading.

Lity.options

Sets or returns options of the instance.

var allOptions = instance.options();

var template = instance.options('template');
instance.options('template', '<div>...</div>');

var closeOnEsc = instance.options('esc');
instance.options('esc', false);

Events

All events receive the Lity instance as the second argument.

Available events

lity:open

Triggered before the lightbox is opened.

$(document).on('lity:open', function(event, instance) {
    console.log('Lightbox opened');
});

lity:ready

Triggered when the lightbox is ready.

$(document).on('lity:ready', function(event, instance) {
    console.log('Lightbox ready');
});

lity:close

Triggered before the lightbox is closed.

$(document).on('lity:close', function(event, instance) {
    console.log('Lightbox closed');
});

lity:remove

Triggered when the closing animation is finished and just before the lightbox is removed from the DOM.

$(document).on('lity:remove', function(event, instance) {
    console.log('Lightbox removed');
});

lity:resize

Triggered when the instance is resized, usually when the user resizes the window.

$(document).on('lity:resize', function(event, instance) {
    console.log('Lightbox resized');
});

License

Copyright (c) 2015-2020 Jan Sorgalla. Released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].