在单击时隐藏Twitter

在单击时隐藏Twitter

本文介绍了在单击时隐藏Twitter Bootstrap导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击时关闭移动导航栏,我看到了问题的答案此处.此问题中给出的代码存在的问题是,无论我们看到切换导航栏还是普通"导航栏,它总是试图关闭导航栏.因此,我想进行一次if/else检查宽度是否大于或小于768px(改变导航栏的宽度),所以我现在将其保存在document.ready()中.

I wanted to close the mobile navbar on click, I see the answer for my questionhere.The problem with the code given in this question is that it's always trying to close the navbar, no matter if we see the toggle navbar or the "Normal" navbar.So I want to do an if/else that check if the width is higher or lower that 768px (the width that changes the navbars), so I have this in my document.ready() right now.

 function close_toggle() {
   if ($(window).width() <= 768) {

    $('.nav a').on('click', function(){
        $(".navbar-toggle").click();
    });
 }
}
close_toggle();

$(window).resize(close_toggle);

此代码的问题是,如果我以大于768px的宽度开始并小于768px,则一切正常.但是,如果我将宽度调整为大于768px时从小于768px的宽度开始,那么当我单击链接时,正常的导航栏就会闪烁(我认为是因为关闭了切换菜单).

The problem with this code is that if I start with a width higher than 768px and go to less than 768px all works good.But if I start with a width lower that 768px when I resize to higher that 768px the normal navbar will blink when I click in the links (because is closing the toggle menu, I think).

所以我需要一个else语句来反转if代码,但是我不知道如何反转该代码.对于某些英语错误,请对不起.希望有人能帮助我.

So I need an else statement to reverse the if code, but I don't know how to reverse that code.Please sorry for some English errors.Hope someone could help me.

推荐答案

查看是否有帮助:

 function close_toggle() {
   if ($(window).width() <= 768) {
      $('.nav a').on('click', function(){
          $(".navbar-toggle").click();
      });
   }
   else {
     $('.nav a').off('click');
   }
}
close_toggle();

$(window).resize(close_toggle);

这篇关于在单击时隐藏Twitter Bootstrap导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:58