Fancy Box 2 automatically closes divs?

jstrat6

So I'm using fancybox 2 on a div. But for some reason, when I click the div and fancybox opens, it hides the div (only showing the outline of the wrapper div), and the only way I can get the div back is to reload the page. Anyone else have this problem? If so, how do I fix it?

I searched google all last night and couldn't find anyone who was having this problem. And after reading the license page I don't think fancybox 2 supports the onClose or onStart attributes.

Here's my div

<div class='photo'><img class='fancybox' src='images/jpge1.jpg></div>
$(document).ready(function()  {
    $('.fancybox).click(function() {
        $('.fancybox').fancybox();
    });
});
JFK

There are a couple of issues with your code (without mentioning the syntax errors : your src attribute and your jQuery selectors are not properly quote closed)

  1. if you bind fancybox to an element other than an anchor <a> then fancybox treats it as inline content and it will always place it back with a display:none property.

  2. When you do

    $(document).ready(function()  {
        $('.fancybox).click(function() {
            $('.fancybox').fancybox();
        });
    });
    

    The first click on .fancybox selector only binds itself to fancybox but it will only fire fancybox after the second click

So if you want to properly bind fancybox to an element other than an anchor (a div in your case) and then open the image (which is inside the div) inside fancybox without hiding it after fancybox is closed, then you have to do:

Bind fancybox to the div by setting the class fancybox to it, not to the img tag

<div class='photo fancybox'>
    <img src='images/jpge1.jpg' />
</div>

Then use this code :

$(document).ready(function () {
    $('.fancybox').click(function () {
        var href = $(this).find("img").attr("src");
        $.fancybox({
            href: href,
            type: "image"
        });
        return false;
    });
});

See JSFIDDLE

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Message box closes automatically after a brief delay

From Dev

VB - Form 2 closes automatically whenever Form 1 closes?

From Dev

Adding fancy box to a WP theme

From Dev

Fancy box not opening second time

From Dev

Fancy box, grab from url

From Dev

Fancy Box does not work on heroku

From Dev

trigger fancy box from div?

From Dev

Application closes automatically

From Dev

Putty - Automatically closes on authentication

From Dev

NSPopover closes automatically

From Dev

Putty - Automatically closes on authentication

From Dev

Content inside fancy box need to be responsive

From Dev

replace default browser confirm with jQuery fancy box

From Dev

Yotpo Reviews Conflict With Jquery Fancy Box

From Dev

Reload window without closing Fancy Box

From Dev

Most 'elegant' way to make 2x2 box of divs

From Dev

Widget opens for a second then automatically closes?

From Dev

FCM push notification closes automatically

From Dev

custom jquery alert closes automatically

From Dev

Divs are being adjusted automatically

From Dev

How to automatically increase the height of select2 input box (multiple)

From Dev

Unable to input text in an input field (in a fancy box popup)

From Dev

Disable Fancy Box Close Function on Cross Icon and on HTML Body Click

From Dev

fancy box youtube only 360p resolution is available

From Dev

First image in fancy box slide show appears twice

From Dev

fancy box not open in single click,require double click

From Dev

How to insert alt tag for fancy box images [ fancyBox3 ]?

From Dev

How to make what the menu will automatically closes?

From Dev

C Win32: Window Automatically closes

Related Related

HotTag

Archive