2015-04-04 49 views
0

我是一個在我個人網站工作,我是一名平面設計師,所以編碼不是我的專長,我一直在尋找答案,但我想也許是我的問題是多一點具體的:jquery - 當擊中div時添加滾動類 - IE和Firefox問題

這個問題很簡單,這是鏈接到我的網站: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是section。

(我正在使用Skeleton進行響應)

謝謝。

回答

0

我不能回覆這個問題,我有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/

+0

您好,我抓住了 「亮點」 的代碼從本教程:http://callmenick.com/post/single-page-site-with-smooth-scrolling-highlighted-link-and-fixed-導航 本教程中的演示頁面在最新的Firefox,最新的Google Chrome瀏覽器和Internet Explorer 11中運行良好,所以我不確定我做錯了什麼。 – 2015-04-07 19:27:40

+0

你的FF版本是什麼? – 2015-04-08 03:39:57

+0

根據Firefox,我使用的Firefox版本是:37.0.1 - 最新版本 - 而IE 11版本是:11.0.9600.16384 – 2015-04-08 17:12:08