平滑滚动表现得很奇怪

时间:2018-01-06 18:38:59

标签: javascript jquery

https://codepen.io/pallavkeshari/pen/eyBmeZ

$(document).ready(function() {

    var scrollLink = $('.scroll');

    scrollLink.click(function(e) {
        e.preventDefault();
        $('body,html').animate({
            scrollTop: $(this.hash).offset().top
        }, 1000 );
    });

    $(window).scroll(function() {
        var scrollbarLocation = $(this).scrollTop();

        scrollLink.each(function() {

            var sectionOffset = $(this.hash).offset().top - 20;

            if ( sectionOffset <= scrollbarLocation ) {
                $(this).parent().addClass('active');
                $(this).parent().siblings().removeClass('active');
            }
        })

    })

})

平滑滚动表现得非常笨拙。从“Home”转到页面的任何其他部分工作得很好,但是当从“简历”说到“项目”时,它没有用完。

0 个答案:

没有答案
相关问题