Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slick-lightbox

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slick-lightbox

[![CDNJS](https://img.shields.io/cdnjs/v/slick-lightbox.svg)](https://cdnjs.com/libraries/slick-lightbox)

  • 0.2.12
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by12.29%
Maintainers
1
Weekly downloads
 
Created
Source

slick-lightbox

CDNJS

A lightbox wrapper for Ken's amazing slick carousel. Credits go to kenwheeler for doing the hard work.

Setup

Bower

bower install -S slick-lightbox

Ruby on Rails

Use the slick-lightbox-rails gem. Add to Gemfile.

gem 'slick-lightbox-rails', '>= 0.0.1'

Run bundler.

bundle install

Usage

Make sure you include CSS for both slick and slick-lightbox. Example HTML:

<!DOCTYPE html>
<html>
<head>
  <title>slick lightbox</title>
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" type="text/css" href="bower_components/slick-carousel/slick/slick.css">
  <link rel="stylesheet" type="text/css" href="bower_components/slick-carousel/slick/slick-theme.css">
  <link rel="stylesheet" type="text/css" href="styles/slick-lightbox.css">
</head>
<body>
  <div>
    <ul>
      <li><a href="http://placekitten.com/1600/1300" data-caption="Lorem ipsum 1600x1300">http://placekitten.com/1600/1300</a></li>
      <li><a href="http://placekitten.com/1630/1280" data-caption="Lorem ipsum 1630x1280">http://placekitten.com/1630/1280</a></li>
      <li><a href="http://placekitten.com/1500/1250" data-caption="Lorem ipsum 1500x1250">http://placekitten.com/1500/1250</a></li>
    </ul>
  </div>
  <script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
  <script type="text/javascript" src="bower_components/slick-carousel/slick/slick.min.js"></script>
  <script type="text/javascript" src="scripts/slick-lightbox.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $('ul').slickLightbox({
        itemSelector: '> li > a'
      });
    });
  </script>
</body>
</html>

Options

OptionTypeDefaultDescription
backgroundstringrgba(0,0,0,.8)Background for the lightbox. Is used directly as a CSS background statement so that color and/or an image can be used.
closeOnEscapebooleantrueShould the lightbox close upon pressing ESC?
closeOnBackdropClickbooleantrueShould the lightbox close upon clicking on backdrop?
destroyTimeoutnumber500How many ms should we wait before actually removing the lightbox from the DOM? The default is used so that a 0.5s opacity transition can take place.
itemSelectorstringajQuery-like selector for the carousel-to-create items. The items should be anchors with href attribute aiming at the desired lightbox image. If that's not the case, you should specify the src option.
navigateByKeyboardbooleantrueCan you use keyboard arrows to navigate the carousel?
slickobject{}Slick options to pass to the carousel.
captionvariousfalseShould the images be captioned? If false, no caption is created. You can pass your own function accepting the element and info attributes (e.g. function(element, info) { return $(element).doSomething(); }, with info being an { index: itemIndex, length: itemCount } object) or a string with the name of the data-attribute to be fetched (my-caption will get the value of data-my-caption attribute).
srcvariousfalseHow to get the image urls? If false, no src is taken as the href attribute. You can pass your own function accepting the element as an attribute (e.g. function(element) { return $(element).doSomething(); }) or a string with the name of the attribute to be fetched (src will get the value of element.src attribute).
captionPositionvarious'dynamic'Where should the caption be placed? When set to 'dynamic', the caption is displayed right under the image. When 'bottom', the caption is on the bottom of the screen independent to the image size.
imagesvariousfalseWhen passed an array, slick lightbox doesn't scan the elements for image URLs and uses array's values instead.
useHistoryApibooleanfalseWhen true, opening the lightbox does a history.pushState. The plugin then listens for the popstate event to close the lightbox.
layoutsobjectSee Layouts
shouldOpenfunctionnullGiven a function, checks the return value before opening. If the function returns a falsy value, the lightbox is not opened upon clicking on the items. Accepts three arguments - the slick lightbox instance as the first, the clicked element as the second and the click event as the last.
imageMaxHeightnumber0.9Maximum height of the lightbox images. Relative to the window height.
lazybooleanfalseShould the images be lazyloaded?
lazyPlaceholderstringnullPath to lazyloading placeholder. Defaults to a blank gif.

Events

Events are triggered on the source element. Example:

$(document).ready(function(){
  $('ul').slickLightbox().on({
    'show.slickLightbox': function(){ console.log('A `show.slickLightbox` event triggered.'); },1
    'shown.slickLightbox': function(){ console.log('A `shown.slickLightbox` event triggered.'); },
    'hide.slickLightbox': function(){ console.log('A `hide.slickLightbox` event triggered.'); },
    'hidden.slickLightbox': function(){ console.log('A `hidden.slickLightbox` event triggered.'); }
  });
});
EventDescription
show.slickLightboxTriggered when the lightbox is opened.
shown.slickLightboxTriggered when the lightbox is opened, after the transitions took place.
hide.slickLightboxTriggered when the lightbox is closed.
hidden.slickLightboxTriggered when the lightbox is closed, after the transitions took place.

Layouts

The layout is customizable using the layouts option object.

  • layouts.closeButton, which defaults to <button type="button" class="slick-lightbox-close"></button>

Lightbox instance

You can access the lightbox instance through the bound element. It's assigned to .slickLightbox. Example:

$('#my-element').slickLightbox()
console.log('My slickLightbox instance:', $('#my-element')[0].slickLightbox)
// once a lightbox is opened
console.log('My slick instance:', $('#my-element')[0].slickLightbox.slick)

Demos

The slick-lightbox demo page contains various setups of slick lightbox.

Contributing

Edit the coffee source please. Use gulp to build.

FAQs

Package last updated on 13 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc