开发者

FancyBox onload show is not working with normal click

开发者 https://www.devze.com 2023-04-08 05:57 出处:网络
I\'m creating a little JavaScript game. When the page loads, it is supposed to display a Fancybox over the page.

I'm creating a little JavaScript game. When the page loads, it is supposed to display a Fancybox over the page.

Here is my jQuery for开发者_如何学Python the Fancybox:

$(document).ready(function() { 
$('#test').fancybox({ 
'transitionIn' : 'elastic',
'transitionOut' : 'elastic', 
'showCloseButton' : false,
'overlayOpacity' : 1
}).click();
});

Here is my HTML:

<a id="test" href="#test2" style="display:none;">Test the Popup</a>
<div style="display:none;">
<div id="test2"  style='padding:10px; background:#fff;width:550px;'>
<b style="color:#FF9C21;font-size:24px;">HTML Jeoprady</b><br>
<span style="font-size:15px;">
You think your good at HTML? Well test your skill here.<br>
Please know there is more to HTML than 2 tags ;)<br>
Are you ready?<br><br>
<b style="color:#FF9C21;font-size:24px;">Name:</b>
<input type="text" id="team1" />
</span>
<br><br>
<span id="start" onclick="loop();" style="cursor:pointer;color:#FF9C21;font-size:20px;"> 

<center>Start Game!</center></span>
</div>
</div>

All of my FancyBoxes that activate onclick show, but then it automatically closes about 5 seconds after it opens.

Is there a way I can fix this?


Instead of .click() you should probably just use .open()

Edit: Silly me, there is no .open(). I have had issues with firing click programmatic click events before. If the method you are trying is causing issues, try this

$('#test').trigger('click')

or alternatively use a manual call

$.fancybox('html content here',{options})


If you did a manual call you could do:

var theContent = $('#div-id').html();

$.fancybox(theContent, {
'transitionIn' : 'elastic',
'transitionOut' : 'elastic', 
'showCloseButton' : false,
'overlayOpacity' : 1
});

And then, the contents of #div-id would be in the manual call.

I hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消