Git Product home page Git Product logo

englishextra / img-lightbox Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 2.0 694 KB

Responsive no-jQuery pure JS/CSS Lightbox for images, no dependencies, 10kb unminified source code, with demo

Home Page: https://codepen.io/englishextra/full/YLQxRp/

License: MIT License

JavaScript 55.14% HTML 24.36% CSS 12.19% Batchfile 0.06% SCSS 8.25%
audiomack browser css front-end frontend html iframe js lightbox no-dependencies

img-lightbox's Introduction

img-lightbox

Responsive no-jQuery pure JS/CSS Lightbox for images, no dependencies, 10kb unminified source code, with demo

npm Build Status Codacy Badge jsdelivr

Demo

codepen jsfiddle jsbin

Features

  • Simple initialization
  • SPA / PWA friendly: prevents multiple same events assigning
  • Debounced launch, default 500ms, custom rate can be set with rate property of options object
  • Preloading spinner that is unset after onload event succeeds
  • Pure CSS Retina Ready UI images, no external ones (prompted by github.com/jasomdotnet, thanks)
  • Custom event callbacks

CDN

jsDelivr

https://cdn.jsdelivr.net/gh/englishextra/img-lightbox@latest/js/img-lightbox.min.js https://cdn.jsdelivr.net/gh/englishextra/img-lightbox@latest/css/img-lightbox.min.css

unpkg

https://unpkg.com/img-lightbox@latest/js/img-lightbox.js https://unpkg.com/img-lightbox@latest/css/img-lightbox.css

Install

npm

npm install img-lightbox

Setup

class is required, and can be any class name you choose (in this demo it's img-lightbox-link). data-src is another method to get the source URL when you do not want the link to lead to some real URL. href is required, and contains URL of your image. For those who don't use 3rd-party scripts that interfere with links behaviour and don't force window.location they have no need in either data-touch="true" or {touch: true}. When you have scripts that interfere, then to keep lightbox working, use {touch: true} or data-touch="true" (you shouldn't enable this touch override if you have a full screen image in a lighbox link and have no other space to scroll down). data-src or href doesn't matter. Build Status

<a href="https://farm1.staticflickr.com/955/27854475488_4f2b7f52e4_k.jpg"
class="img-lightbox-link"
data-src="https://farm1.staticflickr.com/955/27854475488_4f2b7f52e4_k.jpg"
aria-hidden="true"
rel="lightbox"><img src="https://farm1.staticflickr.com/955/27854475488_5f82a379ca_z.jpg" alt="Image Lightbox" /></a>

Initialize

imgLightbox("img-lightbox-link");

Tips

SPA / PWA developers don't need to bother: work-related class is added to a link. That way you avoid multiple assignments to a single element.

Examples of event handling

(function(root) {
  "use strict";
  if (root.imgLightbox) {
    imgLightbox("img-lightbox-link", {
      onCreated: function() {
        /* show your preloader */
      },
      onLoaded: function() {
        /* hide your preloader */
      },
      onError: function() {
        /* hide your preloader */
      },
      onClosed: function() {
        /* hide your preloader */
      },
      rate: 500 /* default: 500 */,
      touch: false /* default: false - use with care for responsive images in links on vertical mobile screens */
    });
  }
})("undefined" !== typeof window ? window : this);

GitHub

englishextra/img-lightbox

License

Available under MIT license.

img-lightbox's People

Contributors

englishextra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

lisinchyk shoora

img-lightbox's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.