Skip to content Skip to sidebar Skip to footer

Fancybox: When Click In Any Part Of Page Open Fancybox

I'm trying to implement a simple thing in my page using jQuery and Fancybox, but I can't put my code to work. I need create a code that when user click in any part of the page, Fa

Solution 1:

If you want fancybox to open when user clicks anywhere in your page after page load (and before they can interact with the page itself) then try

jQuery(document).ready(function ($) {
    // add fancybox class to body on page load
    $("body").addClass("fancyopen");
    // bind click to body
    $(".fancyopen").on("click", function () {
        $.fancybox([{
            href: "/yourpage.html",
            title: "welcome to our website"
        }], {
            width: 300,
            height: 200,
            type: "iframe",
            afterShow: function () {
                $(".fancybox-wrap").on("click", function (event) {
                    event.stopPropagation(); // so you can click fancybox without calling it again
                });
            },
            afterClose: function () {
                $(".fancyopen").unbind("click").removeClass("fancyopen"); // now you can interact with the page
            }
        }); // fancybox
    }); // on
}); // ready

See JSFIDDLE


Post a Comment for "Fancybox: When Click In Any Part Of Page Open Fancybox"