Matt Williams
Matt Williams

Reputation: 79

How can i get this to run as soon as the page is loaded?

I want this fancyBox to run as soon as the page has loaded instead of having to click on a image.

In the javascript code i have:

<script type="text/javascript">
        $(document).ready(function() {

    $(".fancybox").fancybox({

                type : 'image',
                maxWidth    : 800,
                padding     : 0,
                fitToView   : true,
                maxHeight   : 600,
                fitToView   : false,
                width       : '70%',
                height  : '70%',
                autoSize    : true,
                closeClick  : false,
                nextEffect  : 'none',
                closeEffect : 'none',
                mousewheel : true

        });
        });
    </script>

Thanks Guys!

Upvotes: 1

Views: 310

Answers (3)

Rafay
Rafay

Reputation: 31033

you can try a dirty hack

$(document).ready(function() {

    $(".fancybox").fancybox({

                type : 'image',
                maxWidth    : 800,
                padding     : 0,
                fitToView   : true,
                maxHeight   : 600,
                fitToView   : false,
                width       : '70%',
                height  : '70%',
                autoSize    : true,
                closeClick  : false,
                nextEffect  : 'none',
                closeEffect : 'none',
                mousewheel : true

        });
 $(".fancybox").click();
        });

it seems like its the documented way

jQuery(document).ready(function() {
    $("#your_selector").trigger('click');
});

Upvotes: 0

Frederik Wordenskjold
Frederik Wordenskjold

Reputation: 10221

From the documentation:

jQuery(document).ready(function() {
  $("#your_selector").trigger('click');
});

Where your_selector has a fancybox attached to it, so in your case this would be .fancybox.

Upvotes: 1

crush
crush

Reputation: 17013

Assuming that .fancybox is the image in question, $(".fancybox").click() at the end of your $(document).ready(function() {

Upvotes: 2

Related Questions