fatiherdem fatiherdem - 5 months ago 28
jQuery Question

Fancybox 2 auto thumbnail

I am using Fancybox 2 for image gallery. I am trying to figure out how can I make auto thumbnail via source image. In example there are 2 image one of them is original and the other one is thumbnail image. I want to set only original image and Fancybox should create thumbnail automatically.

<p>
<a class="fancybox" rel="gallery1" href="http://farm2.staticflickr.com/1617/24108587812_6c9825d0da_b.jpg"> </a>
<a class="fancybox" style="margin-left: 20px" rel="gallery1" href="http://farm4.staticflickr.com/3691/10185053775_701272da37_b.jpg"></a>
<a class="fancybox" style="margin-left: 20px" rel="gallery1" href="http://farm1.staticflickr.com/574/22407305427_69cc6e845f_b.jpg"></a>
<a class="fancybox" style="margin-left: 20px" rel="gallery1" href="http://farm1.staticflickr.com/291/18653638823_a86b58523c_b.jpg"></a>
</p>


js

$("a.fancybox").fancybox({
openEffect: 'none',
closeEffect: 'none'
});


As you see I didn't specify thumbnails img. Is there any way to create automatically? And my thumbnail count various. It can be between 1-10.

Answer

Something like this?

jQuery('.fancybox').each(function(i,e){
jQuery(e).css('background-image','url('+jQuery(e).attr('href')+')');
});

https://jsfiddle.net/agm65/f5xzaL2s/2/

Comments