jQuery function needs clicking twice
if you visit one of our sites; http://skateboardingphoto.co.uk, you will see that there is a navigation bar at the top which can be hidden or expanded.
When being expanded (expanded by default, so have to minimise first), it needs to be clicked twice, but it would seem only the first time...
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".open-close").click( function() {
if (jQuery("#openClose").is(":hidden")) {
jQuery("#navigation-wrap").removeClass("closed").addClass("open")
.animate({
marginLeft: "0px"
}, 500 );
jQuery.cookie('navbar', 'open', { expires: 1, path: '/' });
jQuery("#openClose").show();
} else {
jQuery("#navigation-wrap").removeClass("open").addClass("closed")
.animate({
marginLeft: "-330px"
}, 500 );
jQuery.cookie('n开发者_如何学Goavbar', 'closed', { expires: 1, path: '/' });
jQuery("#openClose").hide();
}
});
});
</script>
Thanks for your help
This is because you save the state of the toolbar in a cookie and according to the cookie the user see the toolbar hidden or expanded. I think that the code that handles the cookie is this one (add the line i pointed out):
jQuery(document).ready(function() {
var navbarstatus = jQuery.cookie('navbar');
if (navbarstatus == 'closed') {
jQuery("#navigation-wrap").css("margin-left", "-185px");
jQuery("#openClose").hide();//add this line
} else {
return false;
}
if you don't hide that div when you initialize the toolbar, the first time you click on it jQuery("#openClose").is(":hidden")
return false and executes the second part of the code (which hides ("#openClose")
) and so the second time you click everything is correct.
Is it browser specific? The most common reason for this is that the initial state is not correct - it works for me on FF.
Check that the is(:hidden) is being correctly picked up on the first time in the specific browser.
精彩评论