gpt4 book ai didi

jquery - Twitter Bootstrap 3 导航菜单意外行为

转载 作者:搜寻专家 更新时间:2023-10-31 23:28:02 26 4
gpt4 key购买 nike

我正在为我的网站使用 Twitter bootstrap。导航栏链接在点击时激活,但当我滚动到页面的特定部分时,我想要同样的效果。即(链接在点击时变成灰色,当我滚动该部分时我想要相同的效果)

//jQuery 代码

$(document).ready(function() {

$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 50
}, 1000);
return false;
}
}
});
});


$('.nav li a').on('click', function() {
$(this).parent().parent().find('.active').removeClass('active');
$(this).parent().addClass('active');
});


});

我曾尝试使用推特 scrollspy 但由于这行代码 scrollTop: target.offset().top - 50 我遇到了一些问题。示例 当我单击联系人时,它会进入联系人部分,但投资组合链接在导航菜单中处于事件状态。

我的网站: www.nakibmomin.com

最佳答案

尝试为 scrollspy 应用 -60offset,以应用偏移量。 From here

关于jquery - Twitter Bootstrap 3 导航菜单意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25657713/

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