gpt4 book ai didi

javascript - Jquery - 在点击 div 时在滚动上添加类 - IE 和 Firefox 问题

转载 作者:行者123 更新时间:2023-11-28 08:06:47 25 4
gpt4 key购买 nike

我在我的个人网站上工作,我是一名平面设计师,所以编码不是我的强项,我一直在寻找答案,但我认为我的问题可能更具体一些:

问题很简单,这是我网站的链接:http://irvingtesting.byethost5.com/index.html

(是的,我有一堆 js 脚本 :( )

我特别有这个 jquery 代码:

$(document).ready(function(){
var aChildren = $("nav div li").children(); // find the a children of the list items
var aArray = []; // create the empty aArray
for (var i=0; i < aChildren.length; i++) {
var aChild = aChildren[i];
var ahref = $(aChild).attr('href');
aArray.push(ahref);
} // this for loop fills the aArray with attribute href values

$(window).scroll(function(){
var windowPos = $(window).scrollTop(); // get the offset of the window from the top of page
var windowHeight = $(window).height(); // get the height of the window
var docHeight = $(document).height();

for (var i=0; i < aArray.length; i++) {
var theID = aArray[i];
var divPos = $(theID).offset().top; // get the offset of the div from the top of page
var divHeight = $(theID).height(); // get the height of the div in question
if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
$("a[href='" + theID + "']").addClass("nav-active");
} else {
$("a[href='" + theID + "']").removeClass("nav-active");
}
}

if(windowPos + windowHeight == docHeight) {
if (!$("nav div li:last-child a").hasClass("nav-active")) {
var navActiveCurrent = $(".nav-active").attr("href");
$("a[href='" + navActiveCurrent + "']").removeClass("nav-active");
$("nav div li:last-child a").addClass("nav-active");
}
}
});
});

它在 Google Chrome 上工作得很好,但在 IE 和 Firefox 中,.active 类直到滚动位置像在 Div 的中间时才工作在这种情况下,#xportfolio 是一个部分。

(我正在使用 Skeleton 进行响应)

谢谢。

最佳答案

我无法回复这个问题,我有 Firefox 37.0、Firefox Dev Edition 39.0a2 (2015-04-06) 和 Google 44.0.2358.0 canary(64 位)并且它的工作原理相似(使用桌面和响应工具)。

我建议,阅读和学习 MDN 和 Jquery。 https://developer.mozilla.org/en-US/ https://api.jquery.com/scrollTop/

关于javascript - Jquery - 在点击 div 时在滚动上添加类 - IE 和 Firefox 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29452205/

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