javascript - Disable Focus behavior on nav links? - Stack Overflow

Pretty much my problem minus the buttons - my issue applies to anchor links: How to stop buttons from s

Pretty much my problem minus the buttons - my issue applies to anchor links: How to stop buttons from staying depressed with Bootstrap 3

I am using Bootstrap 3 (testing in FF & Chrome), and my .navbar is fixed with a scrollspy function. When I click on a nav link, the link stays in Focused mode (and while scrolling without clicking outside - my nav now shows both links! [1 active/1focus]), and the only way to remove the focus state is to click anywhere outside the nav. Focus state is not a visible issue in Safari.

How would I go about UNfocusing the nav link automatically with mousedown/mouseup instead?

EDIT: Mouseup/mousedown was not the underlying issue as previously thought.

My #nav in case anyone is wondering. Thanks!

<body id="page-top" data-spy="scroll" data-offset="" data-target=".navbar-fixed-top">

   <nav role="navigation" id="nav" class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
                <a class="navbar-brand" href="#page-top">TOP</a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right text-center">
                    <li><a href="#about">ABOUT</a></li>
                    <li><a href="#work">WORK</a></li>
                    <li><a href="#contact">CONTACT</a></li>
                </ul>
            </div>
        </div>
    </nav>

Pretty much my problem minus the buttons - my issue applies to anchor links: How to stop buttons from staying depressed with Bootstrap 3

I am using Bootstrap 3 (testing in FF & Chrome), and my .navbar is fixed with a scrollspy function. When I click on a nav link, the link stays in Focused mode (and while scrolling without clicking outside - my nav now shows both links! [1 active/1focus]), and the only way to remove the focus state is to click anywhere outside the nav. Focus state is not a visible issue in Safari.

How would I go about UNfocusing the nav link automatically with mousedown/mouseup instead?

EDIT: Mouseup/mousedown was not the underlying issue as previously thought.

My #nav in case anyone is wondering. Thanks!

<body id="page-top" data-spy="scroll" data-offset="" data-target=".navbar-fixed-top">

   <nav role="navigation" id="nav" class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
                <a class="navbar-brand" href="#page-top">TOP</a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right text-center">
                    <li><a href="#about">ABOUT</a></li>
                    <li><a href="#work">WORK</a></li>
                    <li><a href="#contact">CONTACT</a></li>
                </ul>
            </div>
        </div>
    </nav>
Share Improve this question edited May 23, 2017 at 11:53 CommunityBot 11 silver badge asked Mar 5, 2015 at 19:48 JennJenn 831 silver badge9 bronze badges 3
  • Why not use the mouseup event and remove the class that causes the focus from all the navbar elements? – VeldMuijz Commented Mar 5, 2015 at 20:21
  • Turns out the focus issue was in the CSS styles and that's why the mouseup events were not working. – Jenn Commented Mar 6, 2015 at 13:36
  • Please see "Should questions include “tags” in their titles?", where the consensus is "no, they should not"! – user57508 Commented Mar 6, 2015 at 13:56
Add a ment  | 

3 Answers 3

Reset to default 5

Particular detail that resolved my dilemma. Now works in FF and Chrome.

The (scrollspy) active link that needed to be styled

.navbar-inverse .navbar-nav > .active > a:focus {color: #262A3A;}

and removed .navbar .nav > li > a:focus {color: red;} that lingered underneath on mousedown.

jquery solution, since you asked for mousedown/mouseup:

$(".navbar-brand").mouseup(function(){
    $(this).blur();
});

https://jsfiddle/re2hLe8r/

If I understood your question correctly you want only to use the .active css class for showing the selected nav. One option would be to override the bootstrap's default color on focused nav's.

.navbar-inverse .navbar-nav>li>a:focus {
    color:#777;
    outline:none; // to remove possible blue borders
}

http://jsfiddle/sygn/3k7e88p9/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742418386a4440188.html

相关推荐

  • javascript - Disable Focus behavior on nav links? - Stack Overflow

    Pretty much my problem minus the buttons - my issue applies to anchor links: How to stop buttons from s

    22小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信