单击“主页”时,Jquery显示的导航栏无法隐藏

时间:2022-12-01 13:43:36

I have a site that has a sort of intro navigation on the home page. When selecting an option, a nav bar appears. I need it to hide again when I click on "Home". The first section of code works properly. It's the second half I'm having trouble with:

我有一个网站在主页上有一种介绍导航。选择选项时,会出现导航栏。当我点击“Home”时我需要再次隐藏它。第一部分代码正常工作。这是下半场我遇到的麻烦:

//Show navbar on page scroll
$(window).bind('scroll', function() {
  $("nav").fadeIn(1400);
  var navSeen = true;
});

//Hide navbar if #home is clicked
$("#home").click(function(){
   $("nav").fadeOut(1400);
   var navSeen = false;
});

Thanks in advance for any help!

在此先感谢您的帮助!

EDIT -- All JS in the file:

编辑 - 文件中的所有JS:

<script type="text/javascript">
$(document).ready(function(){
////////////////////////////////
//Lock Dog in place when scrolling right
var dogLock = $('#dog').position().left;
$(window).scroll(function() {
if(dogLock >= $(window).scrollLeft()) {
    if($('#dog').hasClass('leftLock')) {
        $('#dog').removeClass('leftLock');
    }
} else { 
    if(!$('#dog').hasClass('leftLock')) {
        $('#dog').addClass('leftLock');
    }
}
});
//If the connect tab is open and you click outside, then exit out of it!
var menu_state_ = true;
$('#connect').click( function(e) {
e.preventDefault();
if (menu_state_up){
    menu_state_Down();
} else {
menu_state_Up();
}

return false;
});
$('html').click(function() {
menu_state_Up();
});


function menu_state_Down() {
$("#connect-window").fadeIn(200);
menu_state_up = false;
}
function menu_state_Up() {
$("#connect-window").fadeOut(200);
menu_state_up =true;
}
//Ease into each transition
$(function() { 
$('.link').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
    scrollLeft: $($anchor.attr('href')).offset().left - 300
 },600,'easeInOutExpo');
    event.preventDefault();
});
});
//Big Text Plugin
$('.intro').bigtext();

//If the page has scrolled then display the hidden menu
$(window).bind('scroll', function() {
  $("nav").fadeIn(1400);
  var navSeen = true;
});

//Hide navbar if #home is clicked
$("#home").click(function() {
   $("nav").fadeOut(1400);
   var navSeen = false;
});

//////////////////////////////////////////
});
</script>

1 个解决方案

#1


0  

I resolved this by binding the hide to the clicking of home (the only page on which the menu is hidden), and not the scrolling of the page. Thanks for the help folks!

我通过将hide绑定到home的单击(隐藏菜单的唯一页面)而不是页面的滚动来解决这个问题。谢谢你的帮助!

#1


0  

I resolved this by binding the hide to the clicking of home (the only page on which the menu is hidden), and not the scrolling of the page. Thanks for the help folks!

我通过将hide绑定到home的单击(隐藏菜单的唯一页面)而不是页面的滚动来解决这个问题。谢谢你的帮助!