Search code examples
javascriptlightboxlightbox2

How to use lightbox options?


How I can to use lightbox 2 options? How to include in document? It does not work as specified on the site http://lokeshdhakar.com/projects/lightbox2/#options

<script>
    lightbox.option({
      'resizeDuration': 200,
      'wrapAround': true
    })
</script>


<a class="example-image-link" data-lightbox="example-set" href="pic.png">
  <img style="width: 100%" src="pic.png">
</a>

How do you set the lightbox options?


Solution

  • Make sure you are including both the lightbox.js AND lightbox.css stylesheet.

    You will also need jQuery 1.7 or greater (as stated in step 4 of the Getting Started section of the Lightbox website). You should include the jQuery script before the lightbox script.

    This setup worked for me:

    <!DOCTYPE html>
    <html>
    
    <head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/css/lightbox.css" />
    <script src="jquery-1.11.3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js"></script>
    </head>
    
    <body>
    <a class="example-image-link" data-lightbox="example-set" href="pic.png">
      <img style="width: 100%" src="pic.png">
    </a>
    
    <script>
    lightbox.option({
      'resizeDuration': 200,
      'wrapAround': true
      })
    </script>
    </body>
    
    </html>