Javascript Jquery滚动条,活动类的顶部偏移量
你能帮我做一件我办不到的事吗 我在我的网站上使用了scrolling-nav.js作为顶部菜单-内部、外部等 现在我用这个代码设置偏移量Javascript Jquery滚动条,活动类的顶部偏移量,javascript,jquery,css,scroll,offset,Javascript,Jquery,Css,Scroll,Offset,你能帮我做一件我办不到的事吗 我在我的网站上使用了scrolling-nav.js作为顶部菜单-内部、外部等 现在我用这个代码设置偏移量 $(window).scroll(function() { if ($(".navbar").offset().top > 130) { $(".navbar-fixed-top").addClass("top-nav-collapse"); } else { $(".navbar-fixed-top").removeClass("top
$(window).scroll(function() {
if ($(".navbar").offset().top > 130) {
$(".navbar-fixed-top").addClass("top-nav-collapse");
} else {
$(".navbar-fixed-top").removeClass("top-nav-collapse");
}
});
$(function() {
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top - 130
}, 1500, 'easeInOutExpo');
event.preventDefault();
});
});
但是,当您单击“外部”时,活动类并没有完全在该位置工作
我试着用另一个主题的方法,但我的js知识很差
提前感谢。现在,仅当节的顶部偏移为0时才应用活动类。您可以使用jquery将其更改为其他值,如130。添加此代码:
$(window).scroll(function(){
/* Get id of sections corresponding to top nav menu */
var scroll_sections = []
$('a.page-scroll').each(function(){
scroll_sections.push($(this).attr('href'));
})
for (i in scroll_sections)
{
/* Instead of 0, if the top position offset of section is 130 or less,
we add active class for that section in nav menu */
if ($(scroll_sections[i]).position().top <= $(window).scrollTop() + 130)
{
$('nav li.active').removeClass('active');
$('nav a').eq(i).parent().addClass('active');
}
}
});
$(窗口)。滚动(函数(){
/*获取与顶部导航菜单对应的部分id*/
var scroll_sections=[]
$('a.page-scroll')。每个(函数(){
滚动_sections.push($(this.attr('href'));
})
用于(滚动部分中的i)
{
/*如果截面的顶部位置偏移为130或更小,而不是0,
我们在导航菜单中为该部分添加活动类*/
如果($(滚动部分[i])。位置()你能做一把小提琴吗?帮助你做一把会容易得多。让你更容易访问我的网站,有成千上万的代码行,我不知道到底是哪一行。这把小提琴看起来非常漂亮milarhttp://jsfiddle.net/gUWdJ/1389/ 我需要像在上面的小提琴滚动功能调整到我的js代码。对此感到抱歉s:)是否$($anchor.attr('href'))与导航栏中的callToAction的定位相同?有.offset().top-130用于滚动,我需要为.active设置相同的值,但我不知道如何:/