滚动网站后删除html焦点

时间:2015-12-10 14:25:41

标签: html css html5 css3 responsive-design

我正在玩一些网站模板,我正在使用这个模板 我的问题是,当你单击菜单上的某个项目时,让我们说PRODUCTOS,然后你向上或向下滚动,PRODUCTOS总是保持焦点,除非你点击屏幕使它不聚焦,当我滚动而没有时,我怎么能不聚焦项目点击屏幕?

这是我的css

.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
    background-color: #fa7f86;
}

.navbar-default .nav li a:focus {
    border-radius: 3px;
    color: #fff;
    background-color: #F84E57;
}
.navbar-default .navbar-nav>.active>a {
    border-radius: 0;
    color: #fff;
    background-color: #F84E57;
}
.navbar-default .navbar-nav>.active>a:hover,
.navbar-default .navbar-nav>.active>a:focus {
    color: #fff;
    background-color: #F84E57;
}

这就是HTML,你也可以在上面的链接中看到它

 <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <!-- <a class="navbar-brand page-scroll" href="#page-top" style="max-width: 50%;"><img class="img-responsive" src="img/logo.png" />
                </a> -->
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li class="hidden">
                        <a href="#page-top"></a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#quienessomos">Quiénes Somos</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#productos">Productos</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#inversiones">Inversiones</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#contactanos">Contáctanos</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#puntosdeventa">Puntos de Venta</a>
                    </li>

                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>

1 个答案:

答案 0 :(得分:1)

你可以使用blur(),这与焦点相反:

// add a listener to 'scroll' event
document.addEventListener("scroll", function() {
    // get the active element and call blur
    document.activeElement.blur();
});

或者,因为您正在使用jQuery:

$(document).ready(function() {
    $('body').on('scroll', function() {
        $(':focus').blur();
    });
});