繁体   English   中英

jQuery导航点具有平滑滚动

[英]Jquery waypoints with smooth scroll

我在这里使用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'});

您在将jquery添加到页面之前正在调用此位:

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

抛出$ is not a function错误,并停止执行代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM