2013-05-20 85 views
1

我在這裏遇到了一些JQuery航點問題。即時通訊使用它爲我自動滾動導航我的一個頁面的網站:jquery航行點和光滑滾動

signaturestories.eu

,當我用我的滾輪正常工作。我需要它來改變我的導航項的顏色,只要某個元素到達屏幕的頂部。問題是,當你按下注冊 - >約 - >註冊,然後不改變第三次的顏色。

的script.js:

$('a[href^="#"]').bind('click.smoothscroll',function (e) { 
     e.preventDefault(); 

     var target = this.hash, 
     $target = $(target); 

     $('html, body').stop().animate({ 
      'scrollTop': $target.offset().top-40 
     }, 900, 'swing', function() { 
      window.location.hash = target; 
     }); 
    }); 


var currentMenuObject = ''; 

$('#wrapper').waypoint(function() { 
    $(currentMenuObject).css('color', '#f2e0bd'); 
    currentMenuObject = '#top'; 
    $(currentMenuObject).css('color', 'black'); 
}, { offset: '55'}); 

$('#introarticle').waypoint(function() { 
    $(currentMenuObject).css('color', '#f2e0bd'); 
    currentMenuObject = '#top'; 
    $(currentMenuObject).css('color', 'black'); 
}, { offset: '55'}); 

$('#signsection').waypoint(function() { 
    $(currentMenuObject).css('color', '#f2e0bd'); 
    currentMenuObject = '#signup'; 
    $(currentMenuObject).css('color', 'black'); 
}, { offset: '55'}); 

$('#storyarticle').waypoint(function() { 
    $(currentMenuObject).css('color', '#f2e0bd'); 
    currentMenuObject = '#about'; 
    $(currentMenuObject).css('color', 'black'); 
}, { offset: '55'}); 

回答

2

你加入了jQuery頁面之前調用此位:

$(document).ready(function(){ 
    //jQuery code goes here and will be executed as soon as the page has finished loading 
});  

這將引發$ is not a function錯誤並停止執行代碼。

+0

感謝您注意我!我會立即修復這個錯誤。但是,這仍然不能解決我的問題:/ –

+0

我認爲當它向上滾動時它不會觸及'$ target.offset()。top-40'點,這就是爲什麼鏈接不會改變它的顏色。 – Morpheus

+0

所以偏移應該更高還是更低? –