1

This is probably a simple fix but it is sure stumping me! Anyhow, I am trying to link to a thumbnail gallery using a button class. For example:

Here is my fancybox init code:

  $(document).ready(function() {
    $(".fancybox-thumb").fancybox({
        beforeShow: function(){ 
            $("body").css({"overflow":"hidden"}); 
        }, 
        afterClose: function(){ 
            $("body").css({"overflow":"visible"}); 
        }, 
        padding : 2,
        modal : false,
        prevEffect  : 'fade',
        nextEffect  : 'fade',
        nextSpeed   : 'slow',
        prevSpeed   : 'slow',
        openSpeed   : 'slow',
        closeSpeed  : 'slow',
        helpers : {
            title   : {
                type: 'outside'
            },
            overlay : {
                opacity : 0.8,
                css : {
                    'background-color' : '#000'
                }
            },
            thumbs  : {
                width   : 50,
                height  : 50
            }
        }
    });
});

In my HTML I have the following:

<a class="fancybox-thumb" rel="fancybox-thumb" href="images/weddings/PienkosWed-1649.jpg" title="Image 1 Text">
                    <img src="images/weddings/PienkosWed-1649.jpg" alt="" width="150" /></a>
                <a class="fancybox-thumb" rel="fancybox-thumb" href="images/weddings/PienkosWed-1653.jpg" title="Image 2 Text"></a>
                <a class="fancybox-thumb" rel="fancybox-thumb" href="images/weddings/PienkosWed-1655.jpg" title="Image 3 Text"></a>
                <a class="fancybox-thumb" rel="fancybox-thumb" href="images/weddings/PienkosWed-1657.jpg" title="Image 4 Text"></a>
                <a class="fancybox-thumb" rel="fancybox-thumb" href="images/weddings/PienkosWed-1661.jpg" title="Image 5 Text"></a>
                <a class="fancybox-thumb" rel="fancybox-thumb" href="images/weddings/PienkosWed-1667.jpg" title="Image 6 Text"></a>

This works great, except I want to open the fancybox from a button class like:

<a href="OPEN FANCYBOX" class="button1"><span></span><strong>Launch Picture Gallery</strong></a>

I am not sure how to go about this and any help would be greatly appreciated!

tmparisi
  • 111
  • 1
  • 5
  • 19

2 Answers2

4

Try this:

$('.button1').click(function(e) {
   e.preventDefault();
    $('.fancybox-thumb:eq(0)').click();
});
​

Demo: http://jsfiddle.net/lucuma/Skpyw/2/

lucuma
  • 18,247
  • 4
  • 66
  • 91
2

Add the below click event on document ready.

$("a.button1").click(function(){
  $(".fancybox-thumb").trigger("click");
});
Kundan Singh Chouhan
  • 13,952
  • 4
  • 27
  • 32