fancybox opening when I don't want it to
I'm a Jeopardy game and I'm using the FancyBox lightbox plugin to show all the questions in.
I'm trying to create a bonus question. This question is supposed to pop up once all of the 25 spots are gone. I'm currently using a large if
statement:
if($('#html5_100').is(':hidden') &&$('#html5_200').is(':hidden') &&$('#html5_300').is(':hidden') &&$('#html5_400').is(':hidden') &&$('#html5_500').is(':hidden') &&$('#attr_100').is(':hidden') &&$('#attr_200').is(':hidden') &&$('#attr_300').is(':hidden') &&$('#attr_400').is(':hidden') &&$('#attr_500').is(':hidden') &&$('#tf_100').is(':hidden') &&$('#tf_200').is(':hidden') &&$('#tf_300').is(':hidden') &&$('#tf_400').is(':hidden') &&$('#tf_500').is(':hidden') &&$('#dtag_100').is(':hidden') &&$('#dtag_200').is(':hidden') &&$('#dtag_300').is(':hidden') &&$('#dtag_400').is(':hidden') &&$('#dtag_500').is(':hidden') &&$('#tag_100').is(':hidden') &&$('#tag_200').is(':hidden') &&$('#tag_300').is(':hidden') &&开发者_如何学Go;$('#tag_400').is(':hidden') &&$('#tag_500').is(':hidden')){
$('#bonus').fancybox({
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'hideOnOverlayClick':false,
'hideOnContentClick':false,
'showCloseButton' : false,
'overlayOpacity' : 1
}).click();
}
And I'm trying to use $('#ID').is(':hidden');
I put 25 of these ifs in each Click function for each button. The problem is that once I click submit it opens this fancybox. Is there a way to stop this?
If you need more help understanding I could upload my game and just give you a link to it.
It seems like your code is working, as least for me so maybe the id's don't exist on the page?
Also, maybe a better method to check all if all of those divs are hidden would be to just loop through all of them. This method also makes it easier to add additional questions with minimal effort (demo):
var checkDivs = function() {
var i, j, divs = 'html5 attr tf dtag tag'.split(' ');
// loop through div names
for (i = 0; i < divs.length; i++) {
j = 1;
// loop through all numbered div names (adding 100 each time)
while ($('#' + divs[i] + '_' + (j * 100)).length) {
// check if hidden
if (!$('#' + divs[i] + '_' + (j * 100)).is(':hidden')) {
return false;
}
j++;
}
}
return true;
};
does &&$('#html5_200').is(':hidden')
is like that in your code? you need to change all those "&&$" it to && $('#html5_200').is(':hidden')
(add space between && and $() ),
edit:
whay did you added the .click()
after the call to $('#bonus').fancybox{ ... }
? try to remove this from your code because i thik the call to the .click() function trigger this. if it doesn't help either, i will have to see the rest of your code to figure it out
精彩评论