Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch fancyBox from button click

Im stuck with a little problem with fancyBox v2.

I want to launch fancyBox on button click. Once clicked, it will load all the images from the list (from the src attribute of the ).

I have created this jsfiddle to show what I am trying to do: http://jsfiddle.net/fPFZg/

jQuery(document).ready(function($) {
    $('button').on('click', function() {
        $.fancybox(); 
    });
});

Can anybody see how this would be possible?

like image 641
Aaron Avatar asked May 02 '13 14:05

Aaron


People also ask

How do I open fancyBox on button click?

Once clicked, it will load all the images from the list (from the src attribute of the ). jQuery(document). ready(function($) { $('button'). on('click', function() { $.

How do I know if fancyBox is loaded?

Here is the code: if ($('div#fancybox-frame:empty'). length >0) { alert('it is empty'); $.

What is fancyBox in HTML?

fancybox is designed to display images, video, iframes and any HTML content. For your convenience, there is a built in support for inline content and ajax. Images.


1 Answers

I had the same question and found the following to be a simpler method:

HTML

    <button class="fancybox" value="Open Fancybox">Open Fancybox</button>
    <div class="hidden" id="fancybox-popup-form">
        (your Fancybox content goes in here)
    </div>

jQuery

    $('.fancybox').click(function () {
        $.fancybox([
            { href : '#fancybox-popup-form' }
        ]);
    });

CSS

    .hidden { display: none; }

Further Reading

Fancybox Docs (click the "API Methods" tab, then read up on the first method, which is called "Open").

like image 148
Ryan Burney Avatar answered Sep 28 '22 00:09

Ryan Burney