Ben Wong
Ben Wong

Reputation: 701

jQuery Lightbox2 not working

I don't know why LightBox is not working. When I click on the image, it goes to the link of the page, rather than have the "lightbox" fade-in to show the image. I console.logged and I get no error messages.

P Gallery | View Portfolio

    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="dist/css/lightbox.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="js/script.js"></script>
    <script src="dist/js/lightbox.js"></script>

</head>


        <section>
            <div class="container">
                <h1 id="heading">All Projects</h1>
                <ul id="gallery">
                    <li class="design" ><a href="img/web1.jpg" data-lightbox="example-set" data-title="Project 1" data-desc="abc"><img src="img/web1.jpg"></a></li>
                    <li class="programming" ><a href="img/web2.jpg" data-lightbox="example-set"  data-title="Project 1" data-desc="abc"><img src="img/web2.jpg"></a></li>
                    <li class="cms" ><a href="img/web3.jpg" data-lightbox="example-set"  data-title="Project 1" data-desc="abc"><img src="img/web3.jpg"></a></li>
                    <li class="cms" ><a href="img/web4.jpg" data-lightbox="example-set"  data-title="Project 1" data-desc="abc"><img src="img/web4.jpg"></a></li>
                    <li class="design cms programming" ><a href="img/web5.jpg" data-lightbox="example-set"  data-title="Project 1" data-desc="abc"><img src="img/web5.jpg"></a></li>
                    <li class="design cms programming" ><a href="img/web6.jpg" data-lightbox="example-set"  data-title="Project 1" data-desc="abc"><img src="img/web6.jpg"></a></li>
                </ul>
            </div>
        </section>

Upvotes: 3

Views: 7000

Answers (3)

sybozz
sybozz

Reputation: 937

This problem happens for the dependency of jquery and its proper version.

In my case, I load the lightbox-plus-jquery.min.js before the jquery and other js files at the bottom of the body. That's jsut working fine.

Upvotes: 0

Artem P
Artem P

Reputation: 5333

You can init lightbox on page load:

$(document).ready(function(){
  lightbox.init();
});

Upvotes: 2

Phrozen
Phrozen

Reputation: 559

Load the lightbox javascript file at the end of your body tag. Worked for me. apparently lightbox need the DOM ready to parse the images/links.

Upvotes: 12

Related Questions