4

I am using this lightbox plugin,

http://lokeshdhakar.com/projects/lightbox2/

https://github.com/lokesh/lightbox2/

I have items on the page similar to the example:

<a href="images/image-2.jpg" data-lightbox="my-image">Image #2</a>
<a href="images/image-3.jpg" data-lightbox="my-image">Image #3</a>
<a href="images/image-4.jpg" data-lightbox="my-image">Image #4</a>

it works fine, but I want to change some options, for that according to the documentation http://lokeshdhakar.com/projects/lightbox2/#options it should be

 lightbox.option({
      'resizeDuration': 200,
      'wrapAround': true
    })

however i am getting an error

lightbox.option is not a function

so, how to set the options I need ?

edit: the option snippet I have is AFTER the line where the lightbox js is loaded.

edit2: also the options snippet is inside document ready

edit3: lightbox is loaded and is working fine

dav
  • 8,931
  • 15
  • 76
  • 140
  • 1
    without seeing the full context of where in the page you're setting the option, I can only guess that you're doing it BEFORE lightbox js is loaded – Jaromanda X Jul 26 '15 at 10:01
  • Show us full code with JS /Lightbox loading sequence – TechGuy Jul 26 '15 at 10:02
  • @JaromandaX, i updated the question, as i mentioned the lightbox options script becomes after the min js file – dav Jul 26 '15 at 10:03
  • 1
    lol - I added an answer before I read the SECOND edit :p – Jaromanda X Jul 26 '15 at 10:06
  • What does `console.log(lightbox)` say? – Barmar Jul 26 '15 at 10:06
  • 1
    BTW, there's no need to put `editN` before each update to the question. – Barmar Jul 26 '15 at 10:07
  • You have to provide minimalistic sample replicating your issue or at least a link where this issue can be checked – A. Wolff Jul 26 '15 at 10:08
  • @Barmar, there were questions i wanted to address from the comments, just wanted to show that i added afterwards after their comment, otherwise it would look like that they asked/mentioend a point smth, taht was already in the question. – dav Jul 26 '15 at 10:10
  • Did some testing and this ought to work. Especially if the lightbox itself works, then the options (and `lightbox` and `lightbox.option`) should too. – Bram Vanroy Jul 26 '15 at 10:11
  • @A.Wolff, good point – dav Jul 26 '15 at 10:11
  • @Barmar, `console.log(lightbox)` gives this ` – dav Jul 26 '15 at 10:13
  • thanks everyone for trying to help, when trying to create some standalone code to be able to provide to others, I used the version with `2.8.1` and it worked fine. – dav Jul 26 '15 at 10:22

3 Answers3

4

As it turned out it has something to do with the version, i was using version 2.7.1, I tried with the version 2.8.1 and the error disappeared

dav
  • 8,931
  • 15
  • 76
  • 140
1

I had same problem using npm. I solved it like this.

import lightbox from 'lightbox2/dist/js/lightbox';

window.lightbox = lightbox;

 window.lightbox.option({
        disableScrolling: true,
        fadeDuration:200,
        //other
    });
borchvm
  • 3,533
  • 16
  • 44
  • 45
-1

Change the ID of that <div id="lightbox"> to something else. Browsers automatically turn all IDs into global variables, and this is overwriting the global lightbox object.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 2
    the point is that there is no div with id `lightbox` in my code, it is being created by the lightbox. – dav Jul 26 '15 at 10:19