2

How do I open fancybox via manual call for a gallery in the html not via the jquery options?

This answers the question of opening the gallery manually.

However, what if I want to open a specific image in a gallery? It could be any image in the gallery list. Is there a way to do that?

I have tried this

$("#launcher").on("click", function(){
 $(".fancybox.default").eq(0).trigger("click");
});

where I add an additional class "default" for the image I want to show.

but when I run it, it shows that image but doesn't have next/prev button for gallery.

Community
  • 1
  • 1
developarvin
  • 4,940
  • 12
  • 54
  • 100
  • 1
    refer this link .. it will help you http://stackoverflow.com/questions/10835849/how-do-i-open-fancybox-via-manual-call-for-a-gallery-in-the-html-not-via-the-jqu – Sathish Sep 13 '12 at 07:46
  • @Sathish I already posted that link at the top of my question – developarvin Sep 13 '12 at 07:57

2 Answers2

2

You have to simulate a click on the element you want to focus.

JQuery lets you do this with the .click function (link).

I took the example an let it focus on element of the group. The first method uses the same selector, fancybox used to create the group

<script>
    $(document).ready(function(){
        //get the group of your fancy elements
        var fancygroup = $("a[rel=example_group]");
        
        // get the element you want to focus (e.g the first element)
        var fancyelem = $(fancygroup.get(1));
        
        // simulate a click
        fancyelem.click();
    });
</script>

Alternitvly you can assign an ID to the element you want to focus and simulate a click on it

<p>
    Image gallery (ps, try using mouse scroll wheel)<br />

    <a rel="example_group" href="./example/9_b.jpg" title="Lorem ipsum dolor sit amet"><img alt="" src="./example/9_s.jpg" /></a>

    <a rel="example_group" href="./example/10_b.jpg" title=""><img alt="" src="./example/10_s.jpg" /></a>

    <a id="initthis" rel="example_group" href="./example/11_b.jpg" title=""><img alt="" src="./example/11_s.jpg" /></a>
    
    <a rel="example_group" href="./example/12_b.jpg" title=""><img class="last" alt="" src="./example/12_s.jpg" /></a>
</p>

(id assigned to the thrid a element

and then select the element directly:

<script>
    $(document).ready(function(){   
        $('#initthis').click();
    });
</script>

BR, Stefan

Community
  • 1
  • 1
Stefan
  • 14,826
  • 17
  • 80
  • 143
0

$("#ID").click(function () { $("a[rel=gallerimages]").fancybox({ }).trigger('click'); });

levi
  • 3,451
  • 6
  • 50
  • 86