Fabrice Chapot
Fabrice Chapot

Reputation: 63

My picture hides after closing the fancybox window

I'm trying to use fancyBox and I wonder why when I close the fancyBox window, my element gets a "display:none;" style. Is there any solution to avoid this ?

My html file includes :

<script type="text/javascript" src="../js/jquery.fancybox.pack.js"></script>
<link rel="stylesheet" href="../css/jquery.fancybox.css" type="text/css" media="screen" />

The target element is this:

<div id="cadre" class="planche"><a id="inline" href="#photo"><img src="../img/new/img/1_ADELE_HAENEL_Actress-H.jpg" alt="ADELE HAENEL" id="photo"></a></div>

My Fancybox js is:

$(document).ready(function() {

    /* This is basic - uses default settings */

    $("a#single_image").fancybox();

    /* Using custom settings */

    $("a#inline").fancybox({
        'hideOnContentClick': false
    });

    /* Apply fancybox to multiple items */

    $("a.group").fancybox({
        'transitionIn'  :   'elastic',
        'transitionOut' :   'elastic',
        'speedIn'       :   600, 
        'speedOut'      :   200, 
        'overlayShow'   :   false
    });

});

Upvotes: 6

Views: 8427

Answers (4)

JDandChips
JDandChips

Reputation: 10100

A few things to check first. You should be calling the .fancybox() against the <A> tag, not the image:

Your HTML should be formatted as:

<a href="image-url" class="fancybox" ...>
   <img src="image-url" />
</a>

Your jQ:

$('.fancybox').fancybox()

Secondly, if your URL does not contain a known image extension or data:image string, it will fail the "isImage" call and will not open a fancybox (most likely just fallback to standard behaviour).

isImage function, for your reference (2.1.5):

isImage: function (str) {
    return isString(str) && str.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i);
},

Upvotes: 2

Krishnadas PC
Krishnadas PC

Reputation: 6519

Add a valid href tag to the a element. Below is a simple example for the same. I faced the same issue and fixed with that.

<a class="fancybox" href="http://fancyapps.com/fancybox/demo/1_b.jpg"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt=""/></a>

Then call the fancybox.

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

JsFiddle demo example

http://jsfiddle.net/FM82s/

Upvotes: 6

user4750012
user4750012

Reputation:

Had the same problem.

The solution was to use another class name for the Tag then the tag. Searched for weeks... :/

Upvotes: 0

emanuel.virca
emanuel.virca

Reputation: 598

I had the same problem and the solution was to to populate the href attribute of the a element with a valid href

Upvotes: 14

Related Questions