Wednesday, 15 January 2014

jquery - Fancy Box 2 automatically closes divs? -



jquery - Fancy Box 2 automatically closes divs? -

so i'm using fancybox 2 on div. reason, when click div , fancybox opens, hides div (only showing outline of wrapper div), , way can div reload page. else have problem? if so, how prepare it?

i searched google lastly night , couldn't find having problem. , after reading license page don't think fancybox 2 supports onclose or onstart attributes.

here's div

<div class='photo'><img class='fancybox' src='images/jpge1.jpg></div> class="lang-js prettyprint-override">$(document).ready(function() { $('.fancybox).click(function() { $('.fancybox').fancybox(); }); });

there couple of issues code (without mentioning syntax errors : src attribute , jquery selectors not quote closed)

if bind fancybox element other anchor <a> fancybox treats inline content , place display:none property.

when do

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

the first click on .fancybox selector binds fancybox fire fancybox after sec click

so if want bind fancybox element other anchor (a div in case) , open image (which within div) within fancybox without hiding after fancybox closed, have do:

bind fancybox div setting class fancybox it, not img tag

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

then utilize code :

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

see jsfiddle

jquery fancybox fancybox-2

No comments:

Post a Comment