Reputation: 157
I'm using Lightbox with Rails.
I've did what everyone suggest on stackoverflow with the lightbox-plus-jquery.js file to stop the turbolinks. i.e.
var ready;
ready = function() {
<the downloaded codes>
};
$(document).ready(ready);
$(document).on('page:load', ready);
But my image gallery is still not working, dont think my codes are wrong since all my other JS files works with the above codes?
My html codes:
<a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-3.jpg" data-lightbox="example-set" data-title="Click the right half of the image to move forward."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-3.jpg" alt=""/></a>
<a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-4.jpg" data-lightbox="example-set" data-title="Or press the right arrow on your keyboard."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-4.jpg" alt="" /></a>
<a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-5.jpg" data-lightbox="example-set" data-title="The next image in the set is preloaded as you're viewing."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-5.jpg" alt="" /></a>
<a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-6.jpg" data-lightbox="example-set" data-title="Click anywhere outside the image or the X to the right to close."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-6.jpg" alt="" /></a>
CSS code is the default one downloaded from site.
Anyone successfully used lightbox with rails before? Or could help me crack this case?
Thanks in advance.
Upvotes: 1
Views: 774
Reputation: 744
I had the same problem. It's not a rails issue.
You should put
<script src="lightbox/lightbox-plus-jquery.js"></script>
(or equivalent) to the end of your body tag in the HTML, instead of the head. The problem is that if the script is in the head, it will run before the images are ready to be parsed by the library.
Upvotes: 2