slick-lightbox
Version:
A lightbox wrapper for Ken's amazing slick carousel. Credits go to [kenwheeler](https://github.com/kenwheeler) for doing the [hard work](https://github.com/kenwheeler/slick).
205 lines • 11.2 kB
HTML
<html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Slick-lightbox by mreq</title><link href="gh-pages/stylesheets/bootstrap.css" rel="stylesheet"><link href="gh-pages/stylesheets/bootstrap-theme.css" rel="stylesheet"><link href="gh-pages/stylesheets/tablesaw.stackonly.css" rel="stylesheet"><link href="gh-pages/stylesheets/tablesaw.stackonly.css" rel="stylesheet"><link href="gh-pages/stylesheets/github-highlight.css" rel="stylesheet"><style>.tablesaw-stack td .tablesaw-cell-label, .tablesaw-stack th .tablesaw-cell-label { overflow: hidden; text-overflow: ellipsis; }
h2 { margin-top: 30px; }
@media screen and (max-width: 770px) { .gh-ribbon { display: none; } }
</style><!--if lt IE 9script(src='https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js')
script(src='https://oss.maxcdn.com/respond/1.4.2/respond.min.js')--></head><body><nav class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><button type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" class="navbar-toggle collapsed"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="/slick-lightbox/" class="navbar-brand">Slick lightbox</a></div><div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse"><ul class="nav navbar-nav"><li><a href="#usage">Usage</a></li><li><a href="#options">Options</a></li><li><a href="#events">Events</a></li><li><a href="docs/">Docs</a></li><li><a href="demo/">Demo</a></li></ul></div></div></nav><div class="container"><h1 id="slick-lightbox">slick-lightbox</h1>
<p>A lightbox wrapper for Ken's amazing slick carousel. Credits go to <a href="https://github.com/kenwheeler">kenwheeler</a> for doing the <a href="https://github.com/kenwheeler/slick">hard work</a>.</p>
<h2 id="usage">Usage</h2>
<p>Install via bower.</p>
<pre><code>bower install -S slick-lightbox
</code></pre><p>Make sure you include CSS for both slick and slick-lightbox. Example HTML:</p>
<pre><code class="lang-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>
</code></pre>
<h2 id="options">Options</h2>
<table>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>background</td>
<td>string</td>
<td><code>rgba(0,0,0,.8)</code></td>
<td>Background for the lightbox. Is used directly as a CSS <code>background</code> statement so that color and/or an image can be used.</td>
</tr>
<tr>
<td>closeOnEscape</td>
<td>boolean</td>
<td><code>true</code></td>
<td>Should the lightbox close upon pressing ESC?</td>
</tr>
<tr>
<td>closeOnBackdropClick</td>
<td>boolean</td>
<td><code>true</code></td>
<td>Should the lightbox close upon clicking on backdrop?</td>
</tr>
<tr>
<td>destroyTimeout</td>
<td>number</td>
<td><code>500</code></td>
<td>How 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.</td>
</tr>
<tr>
<td>itemSelector</td>
<td>string</td>
<td><code>a</code></td>
<td>jQuery-like selector for the carousel-to-create items. The items should be anchors with <code>href</code> attribute aiming at the desired lightbox image. If that's not the case, you should specify the <code>src</code> option.</td>
</tr>
<tr>
<td>navigateByKeyboard</td>
<td>boolean</td>
<td><code>true</code></td>
<td>Can you use keyboard arrows to navigate the carousel?</td>
</tr>
<tr>
<td>slick</td>
<td>object</td>
<td><code>{}</code></td>
<td>Slick options to pass to the carousel.</td>
</tr>
<tr>
<td>caption</td>
<td>various</td>
<td><code>false</code></td>
<td>Should the images be captioned? If <code>false</code>, no caption is created. You can pass your own <strong>function</strong> accepting the <code>element</code> and <code>info</code> attributes (e.g. <code>function(element, info) { return $(element).doSomething(); }</code>, with <code>info</code> being an <code>{ index: itemIndex, length: itemCount }</code> object) or a <strong>string</strong> with the name of the <code>data-attribute</code> to be fetched (<code>my-caption</code> will get the value of <code>data-my-caption</code> attribute).</td>
</tr>
<tr>
<td>src</td>
<td>various</td>
<td><code>false</code></td>
<td>How to get the image urls? If <code>false</code>, no src is taken as the <code>href</code> attribute. You can pass your own <strong>function</strong> accepting the element as an attribute (e.g. <code>function(element) { return $(element).doSomething(); }</code>) or a <strong>string</strong> with the name of the attribute to be fetched (<code>src</code> will get the value of <code>element.src</code> attribute).</td>
</tr>
<tr>
<td>captionPosition</td>
<td>various</td>
<td><code>'dynamic'</code></td>
<td>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.</td>
</tr>
<tr>
<td>images</td>
<td>various</td>
<td><code>false</code></td>
<td>When passed an array, slick lightbox doesn't scan the elements for image URLs and uses array's values instead.</td>
</tr>
<tr>
<td>useHistoryApi</td>
<td>boolean</td>
<td><code>false</code></td>
<td>When <code>true</code>, opening the lightbox does a <code>history.pushState</code>. The plugin then listens for the <code>popstate</code> event to close the lightbox.</td>
</tr>
<tr>
<td>layouts</td>
<td>object</td>
<td></td>
<td>See <a href="#layouts">Layouts</a></td>
</tr>
<tr>
<td>shouldOpen</td>
<td>function</td>
<td><code>null</code></td>
<td>Given 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.</td>
</tr>
<tr>
<td>imageMaxHeight</td>
<td>number</td>
<td><code>0.9</code></td>
<td>Maximum height of the lightbox images. Relative to the window height.</td>
</tr>
<tr>
<td>lazy</td>
<td>boolean</td>
<td><code>false</code></td>
<td>Should the images be lazyloaded? </td>
</tr>
<tr>
<td>lazyPlaceholder</td>
<td>string</td>
<td><code>null</code></td>
<td>Path to lazyloading placeholder. Defaults to a blank gif.</td>
</tr>
</tbody>
</table>
<h2 id="events">Events</h2>
<p>Events are triggered on the source element. Example:</p>
<pre><code class="lang-javascript">$(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.'); }
});
});
</code></pre>
<table>
<thead>
<tr>
<th>Event</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>show.slickLightbox</td>
<td>Triggered when the lightbox is opened.</td>
</tr>
<tr>
<td>shown.slickLightbox</td>
<td>Triggered when the lightbox is opened, after the transitions took place.</td>
</tr>
<tr>
<td>hide.slickLightbox</td>
<td>Triggered when the lightbox is closed.</td>
</tr>
<tr>
<td>hidden.slickLightbox</td>
<td>Triggered when the lightbox is closed, after the transitions took place.</td>
</tr>
</tbody>
</table>
<h2 id="layouts">Layouts</h2>
<p>The layout is customizable using the <code>layouts</code> option object.</p>
<ul>
<li><code>layouts.closeButton</code>, which defaults to <code><button type="button" class="slick-lightbox-close"></button></code></li>
</ul>
<h2 id="lightbox-instance">Lightbox instance</h2>
<p>You can access the lightbox instance through the bound element. It's assigned to <code>.slickLightbox</code>. Example:</p>
<pre><code class="lang-javascript">$('#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)
</code></pre>
</div><a href="https://github.com/mreq/slick-lightbox" class="gh-ribbon"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script type="text/javascript">$('table').addClass('tablesaw tablesaw-stack').attr('data-tablesaw-mode', 'stack');</script><script src="gh-pages/javascripts/bootstrap.min.js"></script><script src="gh-pages/javascripts/tablesaw.stackonly.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script><script type="text/javascript">hljs.initHighlightingOnLoad();</script></body></html>