gpt4 book ai didi

html - 滚动网站后删除 html 焦点

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:31 26 4
gpt4 key购买 nike

我正在玩一些网站模板,我正在处理这个我的问题是,当您单击菜单上的一个元素时,假设是 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>

最佳答案

您可以使用 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();
});
});

关于html - 滚动网站后删除 html 焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34204335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com