W
W
Web Lizard2016-03-17 16:24:47
fancyBox
Web Lizard, 2016-03-17 16:24:47

How to apply lightbox to all image links?

Hello!
Here in Fancybox , you can make the fancybox() parameter apply to all links that lead to images, in fact, like this:

jQuery(document).ready(function($){
  var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]');
  select.attr('rel', 'fancybox');
  select.fancybox();
});

Is there any way to make lightbox work the same way? The problem is that lightbox has a different initialization logic, that is, something like this it looks like:
lightbox.option({
      'resizeDuration': 200,
      'wrapAround': true
})

So how do you make it work for image links?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kirenkov, 2016-03-17
@Lizard-108

It will be a rather crooked implementation, but it should work.
Try to approach from the opposite. For initialization, do you need the A tag to have the data-lightbox attribute if its link leads to an image?
You do something like this:

var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]');

select.each(function(index, item){
    item.data("lightbox", "some text");
})

In theory it might work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question