1

我在使用 JQuery 航路点时遇到了一点麻烦。我将它用于我的一页网站上的自动滚动导航:

签名故事.eu

当我使用滚轮时它工作正常。每当某个元素到达屏幕顶部时,我需要它来更改导航项的颜色。问题是当您按注册-> 关于--> 注册时,第三次没有改变颜色。

脚本.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'});
4

1 回答 1

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错误并停止执行代码。

于 2013-05-20T10:27:03.350 回答