Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  148] [ 3]  / answers: 1 / hits: 24680  / 15 Years ago, wed, november 11, 2009, 12:00:00

I have 2 fancyboxes and am trying to open the second from the first (either by button or by closing the first)..



<div id=firstFancybox style=display:none>
<p>I'm the first Fancybox!</p>
<a id=fancyboxButton href=#secondFancybox>Close first Fancybox</a>
</div>

<a id=hiddenLink href=#firstFancybox></a>

<div id=secondFancybox style=display:none>
<p>I'm the second Fancybox!</p>
</div>


The first Fancybox is being activated on page load..



$(document).ready(function() {
$(a#hiddenLink).fancybox({ 'hideOnContentClick': false, 'frameWidth': 300, 'frameHeight': 300 }).trigger('click');
$(a#fancyboxButton).fancybox();
});


I want to be able to open the second fancybox whenever the first one is closed. Or.. open the second one from clicking the button in the first.



How is this achieved? I'm not having much luck binding to events i'm afraid.



-- Lee



UPDATE :



Using callbackOnClose is allowing me to do simple stuff, like alert('hi'), but i've not managed to open another Fancybox yet.



    $(document).ready(function() {
$(a#hiddenLink).fancybox({ 'hideOnContentClick': false, 'frameWidth': 300, 'frameHeight': 300,
callbackOnClose: function() { alert('hi'); }
}).trigger('click');
});

More From » jquery

 Answers
1

Ok, I finally got it to work (my first encounter with fancybox). It seems that callbackOnClose is called upon closing, not after closing. Hence the second fancybox cannot pop up until after the first one closed completely.



The trick? Delay the opening of the second one by using a timer. This is by no means the perfect answer, could behave oddly if timer is set too short, and not ideal if set too long. 100ms works for me. Here's the code.



Script:



$(document).ready(function() {
$(a#hiddenLink).fancybox({ 'hideOnContentClick': false, 'frameWidth': 300, 'frameHeight': 300,
callbackOnClose: function() { window.setTimeout('open2()',100); }
}).trigger('click');
});
function open2(){
$(a#fancyboxButton).fancybox().trigger('click');
}


HTML:



<div id=firstFancybox style=display:none>
<p>I'm the first Fancybox!</p>
<a href=# onclick=open2();>Close first Fancybox</a>
</div>
<a id=hiddenLink href=#firstFancybox><!--for first fancy box--></a>
<a id=fancyboxButton href=#secondFancybox><!--for second fancy box--></a>

[#98333] Sunday, November 8, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Sun, Aug 15, 21, 00:00, 3 Years ago
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
;