JulianJ JulianJ - 1 month ago 6
jQuery Question

How to stop this fancybox opening on load?

I'm trying to figure out why this jQuery code makes a fancybox image open on page load rather than waiting for the user to click on it. How do I have it open when it's clicked on? Here's a fiddle.

<a class="fancybox" id="single_image" href="http://fancyapps.com/fancybox/demo/1_b.jpg" title="title"
width="200">
<img src="http://fancyapps.com/fancybox/demo/1_b.jpg" width="300" alt=""></a>


Jquery

$(document).ready(function() {
$("#single_image").fancybox({
onComplete: function () {
$("#fancybox-img").wrap($("<a />", {
href: this.href, //or your target link
target: "_blank"
}));
}
}).trigger("click");
});

Answer

Remove the .trigger("click");

$(document).ready(function() {
    $("#single_image").fancybox({
        onComplete: function () {
            $("#fancybox-img").wrap($("<a />", {
                href: this.href, //or your target link
                target: "_blank"
            }));
        }
    })
});

Fiddle: http://jsfiddle.net/j14gf3sv/4/

Comments