GithubHelp home page GithubHelp logo

mreq / slick-lightbox Goto Github PK

View Code? Open in Web Editor NEW
229.0 17.0 103.0 781 KB

A lightbox wrapper for Ken's amazing slick carousel.

Home Page: http://mreq.github.io/slick-lightbox/

License: MIT License

JavaScript 15.66% CSS 14.80% HTML 33.51% CoffeeScript 35.91% Shell 0.12%

slick-lightbox's Introduction

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

Option Type Default Description
background string rgba(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.
closeOnEscape boolean true Should the lightbox close upon pressing ESC?
closeOnBackdropClick boolean true Should the lightbox close upon clicking on backdrop?
destroyTimeout number 500 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.
itemSelector string a jQuery-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.
navigateByKeyboard boolean true Can you use keyboard arrows to navigate the carousel?
slick object {} Slick options to pass to the carousel.
caption various false Should 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).
src various false How 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).
captionPosition various '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.
images various false When passed an array, slick lightbox doesn't scan the elements for image URLs and uses array's values instead.
useHistoryApi boolean false When true, opening the lightbox does a history.pushState. The plugin then listens for the popstate event to close the lightbox.
layouts object See Layouts
shouldOpen function null 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.
imageMaxHeight number 0.9 Maximum height of the lightbox images. Relative to the window height.
lazy boolean false Should the images be lazyloaded?
lazyPlaceholder string null Path 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.'); }
  });
});
Event Description
show.slickLightbox Triggered when the lightbox is opened.
shown.slickLightbox Triggered when the lightbox is opened, after the transitions took place.
hide.slickLightbox Triggered when the lightbox is closed.
hidden.slickLightbox Triggered 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.

slick-lightbox's People

Contributors

alexanderlperez avatar av-src avatar herenow avatar honi avatar hotwebmatter avatar hum-n avatar jwir3 avatar mreq avatar yahsieh avatar

Stargazers

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

Watchers

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

slick-lightbox's Issues

Add events

I need to call a function when the lightbox opens and another function when the lightbox closes.

Bootstrap has several events for its modal plugin. I would love to have these for your plugin as well.

Thanks!

Publish on NPM registry

Is there any reason why slick-lightbox is not registered on NPM? The name is currently not taken so a simple npm publish is all that is required.

Tons of dependencies ... are they all needed?

Adding slick-lightbox to my project made my npm production dependencies balloon up from about 10 to what looks like over 100? Is there any reason why this simple lightbox requires so many prouction dependencies ? Is it possible to clean that up?

navigateByKeyboard not working

HI there,

I would like to switch images in the lightbox with keyboard (or even with some arrows if possible). I've set navigateByKeyboard: true, but it doesn't work, the image in the lightbox doesn't change, while the slick change slide.

How can i fix it?
Thank you

Feature Request: Use they same slide index numbers as an 'Existing Slick'

When attaching a slick-lightbox to an existing slick, it would be nice if the slides in the slick-lightbox had the same slide number as their corresponding slide in the original existing slick. Currently the slick-lightbox's slide numbers are generated such that the first slide is always 0 even if the user clicked on slide 3 to launch the slider.

Keeping the slide numbers in sync makes more advanced interactions between the two sliders much easier.

How to reduce margins in lightbox view?

Love this lightbox. Very easy to set up and works beautifully.

One question: how to make the image display bigger on the page? The image has a max-height style set by javascript, and I would like to make it a larger % of the page height.

screenshot 2016-11-29 11 07 03

Existing slick getting too many slides

Hi,

When using the demo "Existing Slick", it's actually getting 2 too many slides as it's getting the cloned ones too. So when you slide through there are duplicates.

This gets even more problematic when showing more than one slide as it clones even more.

Thanks,
Tom

different styles to set containers dimensions

Hi, thank you for your code.

I just faced a problem where I needed to use the lightbox on a page with fixed header, and needed to keep the header visible.

Solution was something like this:

.slick-lightbox,
.slick-lightbox-inner{
  top: map-get($large, header-height); // move the top
   // reset dimensions
  width: auto;
  height: auto;
  // make fullscreen again, but with real space
  bottom: 0;
  right: 0;
}

By only moving the top, you'll end up with uncentered images, because width/height 100% makes the container still as big as the whole window. Instead, we need them to be as the window-top. In other words, the real available space. This is achieved by using top/bottom props on container (and resetting width/height).

I currently tested this solution in ff, chrome, safari, android. IE not yet.

If you'd like, I could test on IE, make the mods to your css, and send you a pull request.

Regards

Use lightbox without slick

Really weird question but I wonder if this plugin can be used to create a lightbox, without any slick stuff in it? Like just regular HTML....

Reason I ask is because I'm currently using slickjs and and another lightbox plugin and it doesn't make sense to include two lightbox-capable plugins. Would be cool to not have to use the other lightbox plugin at all and just use this.

Or...maybe split out the lightbox stuff into a seperate package? What do you think?

Open lightbox from another link

anyway to open the image in the carousel from an external link?

So i have a carousel of images, but below it I also have a list of connected comments that one of the images might have been in. if you click the comment, I want that image to open in the lightbox gallery.

shouldOpen doesn't pass the actual event target to the callback

Items in the slick carousel might have controls added to them. It would be useful to pass the actual event object to the callback so that the event.target can be compared with the selector of a given control.

An example would be a slider with images having a "Remove this image" control and its respective event listener attached. As it is, shouldOpen simply passes the slide itself, making it difficult to prevent both the lightbox being shown and the "Remove this image" event firing.

One image to trigger lightbox?

Hi,

Thanks for a great plugin.

Is it possible to just have one image to trigger the lightbox and show multiple images? I could just load small versions of the images and hide them using CSS but was wondering if there is a more elegant solution?

Applying slick methods to slickLightbox

Im trying to add some functionality so that if a slide is clicked, it will advance to the next slide. With the default slick instance, I can do this with something like:

$('.slick-lightbox-slick-img').click(function() {
$slideshow.slick('slickNext');
});

Is there a way to do that here? I guess Im just trying to access the slick object within the slickLightbox instance.

Set defaults in triggering script

Depending upon certain conditions, I wish to apply different settings via the script I use to trigger slick-lightbox.

I have tried applying the defaults in this script but without success.

What is the suggested method for moving defaults out of the main slick-lightbox.js file?

Here is how I imagined it to work...

$('.view-images ul').slickLightbox({
background: 'rgba(255,0,255,1)',
navigateByKeyboard: false,
itemSelector: 'li img'
});

Provide a minified version.

I wonder if you could provide a minified version with it? Saving some extra bytes and other tool to minify it will be great.
Thanks.

apply slick lightbox to a group of images

In my site there are multiple times i used slick lightbox..When i clicked on an image it will show the image but when click next it will load all the images that i'm using in all slick sliders in the page..can't we group and show images? I initialized plugin using class. is that the problem?

Incompatible with slick 1.5.9 in Safari?

The slick lightbox seems to be buggy when using with current slick.js (1.5.9) in Safari/iOS.
In all our test cases we couldn't swipe within the lightbox until the first element/image has been changed via prev/next-buttons.
The DOM changes on swipe, but still the first element is visible.

Custom UI

Hi,

It would be cool if we could add an element option to take an object. As I'd like a custom close button and there is no way to do this currently, unless I am mistaken.

So we could do.

$slideshow.slickLightbox({ el: { close : '<button type="button" class="slick-lightbox-close"></button>' } });

Then simply after checking if it's set:

this.options.el.close

Thanks,
Tom

Include /src in Bower package

I would love to keep the plugin updated and maintained through bower, but I'm relying on the source less file that isn't included. Please consider changing this.

Captions are not loading

Captions are not loading using the data-caption option - this can be seen in the demo in repo as it is also not working.

URL was changes after open the lightbox

Hi,

i found a "bug?" on my Projekt. When i open a image the URL in Chrome and IE the url was changed.
The url was changed to the base url without any sub-pages.

In Firefox there are no Problem, it also works on Version 0.1.18.

I uses the slickslider and init so:
$('#slick-demo').slick();
$('#slick-demo').slickLightbox({
src: 'src',
itemSelector: '.item img'
});

First image is only half height

I have a php loop loading images into slick slider, so I added slick-lightbox to that gallery and it all works perfectly, but for some reason the very first image I click on to open in a lightbox is displayed only half or even third of its height. When I click on arrows back and forth, all other images load correctly. And if I go back to the first one it also becomes correct height. Only the first lick display is wrong.

Also, if I click and drag on that image, kinda drag the cursor down, height changes to the full as needed. I don't know what kind of trickery is it.

What do you think it could be?

Slick-lightbox not working in rtl direction

Using slick-direction which works fine in ltr but in Arabic locale my direction is rlt in which slick-lightbox is blank and not showing anything.

I search and find solution for slick in rtl cases but not find any solution for slick-lightbox.

Wrong Image when opening lightbox

Hello, thanks for this amazing plugin.

I'll try to explain my Issue:

When I click on an image for the lightbox function, I get another image to show up, instead of the one I clicked, even though the "href" is different, I keep getting the same image as before.

I'm using this

https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.7.1/slick.min.js
https://cdnjs.cloudflare.com/ajax/libs/slick-lightbox/0.2.10/slick-lightbox.min.js

and this in the html file with a <script> tag

$(document).ready(function() {
      $('#eventCarousel').slick({
        prevArrow: '<span class="slick-prev">Previous</span>',
        nextArrow: '<span class="slick-next">Next</span>',
        slidesToShow: 5,
        infinite: true,
        dots: false,
        appendArrows: $('.arrows-wrap'),
        autoplay: true,
        mobilefirst: true,
        responsive: [
          {
            breakpoint: 1024,
            settings: {
              slidesToShow: 3,
              slidesToScroll: 3,
              infinite: true,
            }
          },
          {
            breakpoint: 600,
            settings: {
              slidesToShow: 2,
              slidesToScroll: 2
            }
          },
          {
            breakpoint: 480,
            settings: {
              slidesToShow: 1,
              slidesToScroll: 1
            }
          }
        ]
      });
      $('#eventCarousel').slickLightbox({
        navigateByKeyboard  : true
      });
    });

This is the HTML for the carousel:

<div id="eventCarousel">
              <div class="item">
                <a style="display: block" href="http://jonvilma.com/images/mountain-6.jpg">1</a>
              </div>
              <div class="item">
                <a style="display: block" href="https://www.vancouvertrails.com/images/photos/goat-mountain-4.jpg">2</a>
              </div>
              <div class="item">
                <h4>3</h4></div>
              <div class="item">
                <h4>4</h4></div>
              <div class="item">
                <h4>5</h4></div>
              <div class="item">
                <h4>6</h4></div>
              <div class="item">
                <h4>7</h4></div>
              <div class="item">
                <h4>8</h4></div>
              <div class="item">
                <h4>9</h4></div>
              <div class="item">
                <h4>10</h4></div>
            </div>

It works fine at first, but when the carousel loops one time, I click on the slide with number 1 and I get the image from the slide with number 2, that is the issue.

Any idea what can it be?

Feature Request: Allow the lightbox to be disabled on small screens

Currently I'm using the lightbox on a responsive website, and it's really working great across all screen sizes! However, I think it would be nice to have the ability to disable the lightbox at set screen widths since sometimes, especially on mobile devices, the lightbox version of the picture may be smaller than the original slick version - basically providing no additional value.

Thoughts?

Another option is to expose the ability for someone to cancel the opening of the lightbox inside the 'show.slickLightbox' event.

Update NPM package?

Hey @mreq, the latest version for this package on NPM is 0.2.0 โ€” can you update it? ๐Ÿ™ ๐Ÿ˜

Resizing in Safari with slick-lightbox open causes layout issues (sometimes)

Resizing in Safari with slick-lightbox open sometimes causes layout issues where the pictures are no longer center aligned and may be clipped by the browser.

Steps to reproduce:

  1. Open Safari browser.
  2. Navigate to a demo: http://mreq.github.io/slick-lightbox/demo/
  3. Open a slick-lightbox.
  4. Resize the window.
  5. Optional: Change slides using the keyboard's arrow keys. (Mousing over the slick-next and slick-prev buttons will actually cause the layout to be recalculated and fixes the issue)

The issue doesn't appear to occur in Chrome or Firefox.

bug

Bug: ie9 transition duration is undefined

slick-lightbox: v0.1.12
browser: ie9

Hello,
Line 263 is throwing an error in ie9 -

return this.transitionDuration = duration.indexOf('ms') > -1 ? parseFloat(duration) : parseFloat(duration) * 1000;

Unable to get value of the property 'indexOf': object is null or undefined

This is because duration is undefined at line 262.

duration = this.modalElement.css('transition-duration');

I can fix this by explicitly setting a duration, but was wondering if there could be a better way? Whereabouts do you set the transition duration?

if (duration === undefined) {
    duration = '0.5s';
}

Consider wrapping the plugin with jQuery closure

I got the errors:

Uncaught TypeError: Cannot read property 'fn' of undefined
TypeError: $ is undefined in jquery

Till I wrapped the plugin with the regular closure:

(function($) {

})(jQuery);

I wonder if you could consider wrapping it that way in the next release?
Thanks.

Lightbox is not working while window resize, It happen in some cases

Lightbox work well in our Project. Very much thanks for this valuable plugin. We found some issues while changing window width and height ( It happen when we test responsiveness). Can you add some method to reinitialize while resizing window. I call my function in window resize event but it create more lightbox backgrounds and need to close each one...

Update : This happen when we give different breakpoints in slick

Can you please check this issue..

Thanks in advance

Opening slick lightbox multiple times on enter keypress

Hi, thank you for sharing slick-lightbox! I used it in the project and working well. However, I noticed some unwanted behaviour:
After the slick item (using anchor tags) is clicked, the slick-lightbox appears. Then when there is pressed Enter on the keyboard, the slick-lightbox is opened again. Then It allows to close only the last slick-lightbox.
It is caused by focus on the slick item. I handled this behaviour catching the show event and blurring particular anchor tag:

$('#slick-slider').on('show.slickLightbox', function(evt) {
    $(evt.currentTarget).find('a:focus').blur();
});

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.