THE original Lightbox script (v2).

Overview

Lightbox2

The original lightbox script.

Lightbox is small javascript library used to overlay images on top of the current page. It's a snap to setup and works on all modern browsers.

  • Demos and usage instructions. Visit the Lightbox homepage to see examples, info on getting started, script options, how to get help, and more.
  • Releases and Changelog. Viewable on the Github Releases page
  • Roadmap. View the Roadmap for a peek at what is being planned for future releases.
  • License. Lightbox is licensed under the MIT License. Learn more about the license.

by Lokesh Dhakar


Info for Maintainers

Local development

  • Install Bower and Grunt.
  • Install jQuery dependency with Bower: bower install
  • Start local server: grunt
  • Navigate to localhost:8000/examples
  • Update examples/index.html to load src/js/lightbox.js and jQuery.
Comments
  • Size (ratio) of image preview is incorrect

    Size (ratio) of image preview is incorrect

    Hi,

    I'm using the lightbox-2.6 library and I have a problem with the size of the image in the popup.

    The image is of a 4:3 ratio but it is displayed in the wrong ratio.

    Here is the generated html for the popup preview:


    <div id="lightbox" class="lightbox" style="display: block; top: 122px; left: 0px;">
        <div class="lb-outerContainer" style="width: 266px; height: 490px;">
            <div class="lb-container">
                <img class="lb-image" src="/LD/Photos/ylmcjjxq.jpg" style="display: block; width: 642px; height: 482px;">
                <div class="lb-nav" style="display: block;">
                    <a class="lb-prev" href="" style="display: block;"></a>
                <a class="lb-next" href="" style="display: block;"></a>
            </div>
            <div class="lb-loader" style="display: none;">
                <a class="lb-cancel"></a>
            </div>
        </div>
    </div>
    <div class="lb-dataContainer" style="display: block; width: 266px;">
        <div class="lb-data">
            <div class="lb-details">
                <span class="lb-caption" style="display: none;"></span>
                <span class="lb-number">Image 7 of 10</span>
            </div>
            <div class="lb-closeContainer">
                <a class="lb-close"></a>
            </div>
        </div>
    </div>
    
    ##

    The lb-outerContainer seems to be the problem

    <div class="lb-outerContainer" style="width: 266px; height: 490px;">
    

    because the size of the img tag has the correct ratio

    <img class="lb-image" src="/LD/Photos/ylmcjjxq.jpg" style="display: block; width: 642px; height: 482px;">
    

    Thanks for your work and help.

    opened by lsicotte 32
  • Overlay sometimes didn´t appear in Chrome

    Overlay sometimes didn´t appear in Chrome

    Hello, I have problem with lightbox overlay on my web page. It works fine in IE, FF, but in Chrome sometimes didn´t apper. I read all this issues, but I didnť find the solution. I tested it with the F12 console and it seems everything OK. The "display: none" and "display: block" changes how should. In the case, that overlay isn´t visible, it just change size of the window, or move mouse in the console over different div and this "refreshing" of page will appear the overlay. Can you help me please?

    P.S. I had a problem with overlay too, that its hight wasn´t over whole page, but I fixed it, when I change overlay position from absolute to fixed in css. Do you think, it is some relationship between this bugs?

    opened by PeterWalk 24
  • Add Video to lightbox

    Add Video to lightbox

    Hello,

    Is it possible to add video content to lightbox? Then you can play a video with overlay and you can see the video's between the pictures? I think this would be a huge advantage for lightbox.

    Best regards, Kris Thienpont

    [type] feature-request 
    opened by bedrijvenabcNMCT 21
  • Changes to make lightbox2 work with jQuery 1.9.0

    Changes to make lightbox2 work with jQuery 1.9.0

    Hi, i tried to use lightbox2 with jQuery 1.9.0 and it not show images, just create the overlayBackgound..

    I changed some lines and make it work.

    jQuery.fn.attr() is deprecated and not exists in jQuery 1.9.0. But the solution is simple, just change any

    $obj.attr('...')
    

    for

    $obj.prop('...')
    

    The second and last change is the way you create de DOM Elements. In build function just change:

    $("<div>", {
            id: 'lightboxOverlay'
          }).after($('<div/>', {
            id: 'lightbox'
          }).append($('<div/>', {
            "class": 'lb-outerContainer'
          }).append($('<div/>', {
            "class": 'lb-container'
          }).append($('<img/>', {
            "class": 'lb-image'
          }), $('<div/>', {
            "class": 'lb-nav'
          }).append($('<a/>', {
            "class": 'lb-prev'
          }), $('<a/>', {
            "class": 'lb-next'
          })), $('<div/>', {
            "class": 'lb-loader'
          }).append($('<a/>', {
            "class": 'lb-cancel'
          }).append($('<img/>', {
            src: this.options.fileLoadingImage
          }))))), $('<div/>', {
            "class": 'lb-dataContainer'
          }).append($('<div/>', {
            "class": 'lb-data'
          }).append($('<div/>', {
            "class": 'lb-details'
          }).append($('<span/>', {
            "class": 'lb-caption'
          }), $('<span/>', {
            "class": 'lb-number'
          })), $('<div/>', {
            "class": 'lb-closeContainer'
          }).append($('<a/>', {
            "class": 'lb-close'
          }).append($('<img/>', {
            src: this.options.fileCloseImage
          }))))))).appendTo($('body'));
    

    for:

    $("<div id='lightboxOverlay'></div><div id='lightbox'><div class='lb-outerContainer'><div class='lb-container'><img class='lb-image' src='' ><div class='lb-nav'><a class='lb-prev' href='' ></a><a class='lb-next' href='' ></a></div><div class='lb-loader'><a class='lb-cancel'><img src='" + this.options.fileLoadingImage + "'></a></div></div></div><div class='lb-dataContainer'><div class='lb-data'><div class='lb-details'><span class='lb-caption'></span><span class='lb-number'></span></div><div class='lb-closeContainer'><a class='lb-close'><img src='" + this.options.fileCloseImage + "'></a></div></div></div></div>").appendTo($('body'));
    

    I forked your project but don't know coffeescript and don't want to mess up your project.. I Hope it help you someway.. Thanks

    opened by fernandosavio 20
  • Images starting at last

    Images starting at last

    I used your tutorial and got ligthbox2 to work on my website. However, it loads my last image first. So when I click on the link it will start at image 4 of 4. I have read other posts with this issue, but am having a hard time making sense of them. I have attached an image of my code, can you help me out?

    capture

    opened by gpeth398 16
  • Center lightbox vertically

    Center lightbox vertically

    Hi,

    as far as i can get from the code the lightbox is currently positioned like this:

    top = $window.scrollTop() + $window.height() / 10;

    so at a certain position from the top of the current position. Is there a way to display the lightbox centered in the window. And also center it again on image change (otherwise if the new image has a different height it won't be centered anymore).

    I tried working it out but did not get to change it. Would appreciate any help! Best, Pascal

    opened by thepascalheynol 16
  • support for downloading image

    support for downloading image

    The image loads and everything is fine. But my users would like to be able to save the image after it loads (some other scripts allow right clicking, dragging the image, etc.). Is there anyway to add this feature to this?

    Until then can't use it :(.

    opened by kalvish21 16
  • Disable Scrolling scrolls to top when image is clicked.

    Disable Scrolling scrolls to top when image is clicked.

    Why does clicking the image to open the modal scrolls the page to the top when disableScrolling is true?

    To produce the following bug, go to Lightbox Examples, open the console, and enter the following.

    lightbox.option({ disableScrolling: true });
    

    Then before clicking an image, scroll so that you're not at the top of the page but you should still see the image (so you could click it tho).

    After clicking, you can see that the modal opens but the page scrolls up, leaving the modal down there! Are there other things that I should do when implementing disableScrolling?

    [type] bug [status] pending release 
    opened by wreighsantos 14
  • Getting it to work with all images in a WordPress theme

    Getting it to work with all images in a WordPress theme

    Hey

    I like the lightbox you have created! I am working on using the correct code to add this to my child theme functions.php file. It would be great to have it work with WordPress. I will also add it to my article on using lightboxes without using a plugin: http://easywebdesigntutorials.com/adding-a-lightbox-to-wordpress-without-using-a-plugin/ (An article still being shaped.)

    What I got right now based on earlier code used with Colorbox, Nivo and Fluidbox (more or less functioning. It looks best with Colorbox. Not that the site is working with it right now though. I am creating an update that I will add onto the site).

    I want to get it working with Lightbox 2. It would also help whomever else is looking for the same thing.

    What is off with the following code? Could you add the code to get it working with WordPress? Btw are there some settings on can adjust to customize the lightbox further?

    /\* Enqueue lightbox 2 - http://lokeshdhakar.com/projects/lightbox2/ */ add_action( 'wp_enqueue_scripts', 'enqueue_lightbox2' ); function enqueue_lightbox2() {
    wp_enqueue_style( 'lightbox2-css', get_bloginfo( 'stylesheet_directory' ) . '/lightbox2/css/lightbox.css', array(), CHILD_THEME_VERSION );
    
    wp_enqueue_script( 'lightbox2', get_bloginfo( 'stylesheet_directory' ) . '/lightbox2/js/lightbox.min.js', array( 'jquery' ), '2.7.1' );
    
    wp_enqueue_script( 'lightbox2-init',  get_stylesheet_directory_uri() . '/lightbox2/lightbox2-init.js', array( 'lightbox2' ), '1.0.0', true );
    

    }

    I then made the init.js file:

    jQuery(function( $ ){ $("a[href$='.jpg'],a[href$='.png'],a[href$='.gif']").lightbox2(); $('a.gallery').lightbox2(); });

    Have a great day!

    opened by paaljoachim 14
  • Lightbox loader shows up in bottom center of screen

    Lightbox loader shows up in bottom center of screen

    When the height of my window is large enough this appears:

    screen shot 2013-09-05 at 3 15 08 pm

    When I change left to: -10000px then it disappears. I don't know the codebase well enough to know if it causes other problems but appears to work. screen shot 2013-09-05 at 3 24 14 pm

    [status] needs review 
    opened by clouddueling 14
  • Lightbox 2.6: Left/Right Navigation Doesn't Show in IE

    Lightbox 2.6: Left/Right Navigation Doesn't Show in IE

    When using an imageset the left and right navigation arrows don't show in IE8/9/10 unless you move the mouse over the thin border around the lightbox first. You can see the behavior using the examples on your site. Pick an image from the imageset then quickly move the mouse into the lightbox. If you move it quick enough the navigation won't appear. If you move it slow enough over the border they will appear. If it appears and you move the mouse over to opposite side, that navigation won't appear and both are gone now and won't re-appear unless you hover over the lightbox border.

    Firefox and Chrome work as expected.

    opened by RhinonMike 12
  • Right side of images covered up

    Right side of images covered up

    I'm using Lightbox on Moodle 3. When opening images with the gallery open, the right half of images is covered up with a solid pink color. If I mouseover the pink area, the whole image becomes visible. When the mouse pointer is moved outside the right half of the image, the pink cover returns, and only the left half of the image is visible. Is this a known bug?

    opened by tomtinker 1
  • seo

    seo

    🐛 Github issues is for bugs only. No feature requests or support tickets please.

    Trouble using Lightbox?

    1. Search Stackoverflow to see if other people have run into similar issues.
    2. If you don't find anything similar, then post a new question on Stackoverflow. Use the lightbox2 tag.

    Have a Feature Request?

    1. Search through existing Github Issues and PRs to see if the feature has been discussed or already created.
    2. If not, search Stackoverflow to see if other people have made similar requests.
    3. If your feature request is unique, then post a new question on Stackoverflow. Use the lightbox2 tag.

    View the project Roadmap.

    Found a Bug?

    Search through existing Github Issues that have been reported to avoid creating a duplicate issue. If your bug has not been reported, create a new issue with the following details:

    What version of Lightbox2 you are using?

    Which browsers and operating systems have you seen the issue on?

    What are the steps to reproduce the bug?

    Do you have link to a live site where the bug is visible? or can you post relevant HTML, CSS, and Javascript?

    opened by polaura 0
  • Uncaught SyntaxError: Unexpected end of input lightbox-plus-jquery.js:9980

    Uncaught SyntaxError: Unexpected end of input lightbox-plus-jquery.js:9980

    Hi, I spotted that lightbox will simply not work, when using lightbox-plus-jquery.js file. The console gives the error: Uncaught SyntaxError: Unexpected end of input lightbox-plus-jquery.js:9980 When used lightbox-plus-jquery.min.js then all is fine.

    What version of Lightbox2 you are using?

    I am using v2.11.3.

    Which browsers and operating systems have you seen the issue on?

    Chrome Version 105.0.5195.102 (Official Build) (64-bit) Windows 10 Enterprise

    What are the steps to reproduce the bug?

    Just use lightbox-plus-jquery.js and check the console in Chrome.

    Do you have link to a live site where the bug is visible? or can you post relevant HTML, CSS, and Javascript?

    No.

    opened by MSzajowka 0
  • Missing Input Sanitization for Image Titles

    Missing Input Sanitization for Image Titles

    What version of Lightbox2 you are using? 2.11.3 (latest)

    Which browsers and operating systems have you seen the issue on?

    • Google Chrome
    • Microsoft Edge

    What are the steps to reproduce the bug? If lightbox2 is used and image data-titles contain unsafe characters such as JS or HTML code, the code will later be executed in the browser if the image is overlayed on the page. Problem is a lack of sanitization when the title is embedded into the "lb-caption" class HTML span object. This might be introduced by file upload functions when the file name is set as title and not properly sanitized.

    image

    The issue was identified in a project that uses lightbox2 for image overlaying. Please see https://github.com/drakkan/sftpgo/issues/981#issuecomment-1244116517 for more information.

    Do you have link to a live site where the bug is visible? or can you post relevant HTML, CSS, and Javascript? https://codesandbox.io/s/lightbox2-demo-forked-vh88tp

    opened by l4rm4nd 0
  • Add positionLBMiddle's option to options

    Add positionLBMiddle's option to options

    when this option is true, image vertically center in any screen

    Pull Requests are welcome. But v2 of Lightbox is in Maintenance Mode. No new features are planned. See the Roadmap.

    PRs submitted will still be reviewed and kept open for others to utilize.

    opened by mrfriend212 0
  • Releases(v2.11.3)
    • v2.11.3(Jul 11, 2020)

    • v2.11.2(Jul 7, 2020)

    • v2.11.1(Jul 14, 2019)

      • #557 Bugfix - MaxHeight wouldn't work. Fix by @RuiBandarra
      • #660 fix: use max[Width|Height] when fitImagesInViewport is false. Fix by @k-iwanishi
      • #664 feature: Prevent Esc keypress from bubbling. Requested by @rkyoku in #663
      Source code(tar.gz)
      Source code(zip)
    • v2.11.0(Apr 22, 2019)

      • #552 SVGs without width and height attrs incorrectly sized in IE11 and older Firefox. PR: #649
      • #621 Remove alpha kbd aliases for closing and nav (x/c/o/n/p). Keep ESC and arrows. https://github.com/lokesh/lightbox2/commit/9ea5e60c00ee334b5d8971ab3e00ba480406775e
      • #620 Disable Scrolling scrolls to top when image is clicked. PR: #650
      • Adds empty alt text for placeholder image. PR: #634 by @Nhawdge
      • Add aria-labels to prev and next images. Problem and fix by @elohanlon PR: #651
      • #520 Toggling visibility of elements on open/close revealing intentionally hidden elements. PR: #652
      • #635 Caption links handlers doesn't trigger. PR: https://github.com/lokesh/lightbox2/pull/653
      • Fixed images size when changing positionFromTop. Fix by @martijndebruijn PR: #654
      Source code(tar.gz)
      Source code(zip)
    • v2.10.0(Nov 26, 2017)

      • [Fix] disable scrolling option not working on iOS https://github.com/lokesh/lightbox2/pull/611
      • [Fix] Remove image files from bower json main prop https://github.com/lokesh/lightbox2/pull/613
      • [Fix] Prevent dupe lightbox DOM elements from being created on multiple calls of lighbox.init() https://github.com/lokesh/lightbox2/pull/615
      • [Change] Update bower.json's jquery dep requirement from ~2 to 2> https://github.com/lokesh/lightbox2/pull/614
      • [Change] Remove image preloading in css. Not req. https://github.com/lokesh/lightbox2/pull/612
      Source code(tar.gz)
      Source code(zip)
    • v2.9.0(Oct 30, 2016)

      • [Fix] Allow loading of lightbox.js anywhere on page. Prev requirement was at the end of the body tag. Commit
      • [Add] Add imageFadeDuration option. Commit
      • [Change] Right-clicking image now shows context menu for image. Commit
      • [Change] Allow controlling of image border with a simpler css border vs a parent container padding hack. Commit
      Source code(tar.gz)
      Source code(zip)
    • v2.8.2(Dec 14, 2015)

    • v2.8.1(Jul 9, 2015)

    • v2.8.0(Jun 30, 2015)

    • v2.7.4(Jun 24, 2015)

      • [Change] Revert jquery dep version to 2.x from 1.x. Added note to Lightbox page about using jQuery 1.x to get IE6, 7, and 8 support.
      • [Fix] Preserve author and license comments from lightbox.js in minified files.
      Source code(tar.gz)
      Source code(zip)
    • v2.7.3(Jun 23, 2015)

      • [Add] Barebone HTML file with examples /examples/index.html.
      • [Add] jquery.lightbox.js which concatenates jQuery and Lightbox. This is for those who are Bower averse or want an extra easy install.
      Source code(tar.gz)
      Source code(zip)
    • v2.7.2(Jun 17, 2015)

      • [Add] maxWidth and maxHeight options added #197
      • [Add] Enable target attribute in caption links #299
      • [Change] Switched to The MIT License from Creative Commons Attribution 4.0 International License.
      • [Change] Add CSS and images to bower.json main property.
      • [Change] Dropped version property from bower.json. #453
      • [Change] Use src -> dist folder structure for build.
      • [Fix] Remove empty src attribute from img tag #287
      • [Fix] Correct grammatical error in comment #224
      • [Fix] Clear the jquery animation queue before hiding the .lb-loader #309
      • [Remove] Remove releases's zips from repo.
      Source code(tar.gz)
      Source code(zip)
    • 2.7.1(Mar 30, 2014)

    • v2.7.0(Mar 30, 2014)

      Features

      • Set caption with data-title or title attribute
      • Support wrapAround option with keyboard nav
      • Make next click target bigger than prev
      • Add option: positionFromTop
      • Add option: alwaysShowNavOnTouchDevices

      Bug fixes

      • Fix #116: .lb-dataContainer fade in bug
      • Fix: Overlay causing horizontal scrollbar on resize
      • Removed the resizeDuration if there is no resize nessesary

      Dev workflow

      • Back to plain ole Javascript from Coffeescript
      • Back to plain ole CSS from SASS for lightbox CSS
      • Upgrade jQuery
      • Switch to Grunt from Rake

      Demo page

      • Design page design refresh
      Source code(tar.gz)
      Source code(zip)
    • v2.6(Jul 7, 2013)

      • Support for latest versions of jQuery.
      • New @fitImagesInViewport option. Set to 'true' by default.
      • New @wrapAround option. Set to 'false' by default.
      • Support for HTML5 valid data-lightbox attribute alongside rel="lightbox".
      • Moved close and loading images references out of js and into css
      • FIX: Incorrect loader image jQuery reference causes loading spinner to only appear once.
      • Redesigned and simpler demo page.
      Source code(tar.gz)
      Source code(zip)
    • v2.5-no-ie8-support(Jul 7, 2013)

      • Switch to jQuery from Prototype and Scriptaculous
      • Switch from Javacript to Coffeescript
      • Switch from CSS to SASS
      • Repo created on Github. :+1:
      Source code(tar.gz)
      Source code(zip)
    Light and responsive lightbox script with focus on performance.

    Magnific Popup Repository Fast, light and responsive lightbox plugin, for jQuery and Zepto.js. Documentation and getting started guide. Examples and p

    Dmitry Semenov 11.3k Jan 2, 2023
    :zap: Simple and easy to use lightbox script written in pure JavaScript

    baguetteBox.js Simple and easy to use lightbox script written in pure JavaScript. Demo page Table of contents Features Installation Importing Usage Cu

    Marek Grzybek 2.3k Jan 3, 2023
    jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

    fancyBox jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable. See the project page for doc

    Jānis Skarnelis 7.2k Jan 2, 2023
    A light-weight, customizable lightbox plugin for jQuery

    About Colorbox: A customizable lightbox plugin for jQuery. See the project page for documentation and a demonstration, and the FAQ for solutions and e

    Jack Moore 4.8k Dec 29, 2022
    A touchable jQuery lightbox

    Swipebox A touchable jQuery lightbox. View project page What is Swipebox ? Swipebox is a jQuery "lightbox" plugin for desktop, mobile and tablet. Feat

    null 2k Dec 6, 2022
    A customizable, modular, responsive, lightbox gallery plugin.

    lightGallery A customizable, modular, responsive, lightbox gallery plugin for jQuery. Demo JQuery lightGallery demo. Codepen demo Main features Fully

    Sachin N 5.6k Jan 4, 2023
    Touch-friendly image lightbox for mobile and desktop

    Touch-friendly image lightbox for mobile and desktop

    Andre Rinas 938 Jan 5, 2023
    Bootstrap-Lightbox - Simple & lightweight lightbox for Bootstrap 5

    Bootstrap-Lightbox Simple & lightweight lightbox for Bootstrap 5 Basic Usage Adding data-modal="bs-lightbox" in your A href tag. <a data-modal="bs-lig

    null 1 Oct 11, 2022
    ⚡️The Fullstack React Framework — built on Next.js

    The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

    ⚡️Blitz 12.5k Jan 4, 2023
    Light and responsive lightbox script with focus on performance.

    Magnific Popup Repository Fast, light and responsive lightbox plugin, for jQuery and Zepto.js. Documentation and getting started guide. Examples and p

    Dmitry Semenov 11.3k Jan 2, 2023
    :zap: Simple and easy to use lightbox script written in pure JavaScript

    baguetteBox.js Simple and easy to use lightbox script written in pure JavaScript. Demo page Table of contents Features Installation Importing Usage Cu

    Marek Grzybek 2.3k Jan 3, 2023
    jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

    fancyBox jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable. See the project page for doc

    Jānis Skarnelis 7.2k Jan 2, 2023
    Low-level CSS Toolkit – the original Functional/Utility/Atomic CSS library

    Basscss Low-level CSS toolkit – the original Functional CSS library https://basscss.com Lightning-Fast Modular CSS with No Side Effects Basscss is a l

    Basscss 5.8k Dec 31, 2022
    Our original Web Component library.

    Polymer ℹ️ Note: This is the current stable version of the Polymer library. At Google I/O 2018 we announced a new Web Component base class, LitElement

    Polymer Project 21.9k Jan 3, 2023
    A light-weight, customizable lightbox plugin for jQuery

    About Colorbox: A customizable lightbox plugin for jQuery. See the project page for documentation and a demonstration, and the FAQ for solutions and e

    Jack Moore 4.8k Dec 29, 2022
    A touchable jQuery lightbox

    Swipebox A touchable jQuery lightbox. View project page What is Swipebox ? Swipebox is a jQuery "lightbox" plugin for desktop, mobile and tablet. Feat

    null 2k Dec 6, 2022
    A customizable, modular, responsive, lightbox gallery plugin.

    lightGallery A customizable, modular, responsive, lightbox gallery plugin for jQuery. Demo JQuery lightGallery demo. Codepen demo Main features Fully

    Sachin N 5.6k Jan 4, 2023
    :clock8: The original jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago").

    timeago: a jQuery plugin Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "ab

    Ryan McGeary 3.8k Dec 25, 2022
    mutate a copy of data without changing the original source

    immutability-helper Mutate a copy of data without changing the original source Setup via NPM npm install immutability-helper --save This is a drop-in

    Moshe Kolodny 5.1k Dec 29, 2022
    Touch-friendly image lightbox for mobile and desktop

    Touch-friendly image lightbox for mobile and desktop

    Andre Rinas 938 Jan 5, 2023