j查询滚动到锚点无法正常工作



我有以下链接:http://www.alessandrosantese.com/test/aldemair-productions/project.html

我正在使用它滚动到带有 id 的特定div:

        $('.project-nav a').on('click', function(e){
            e.preventDefault();
            var anchor = $(this).attr('data-id'),
            el = $('#' + anchor);
            $('html, body').animate({ scrollTop: el.offset().top}, 500);
        });

几乎正常工作,它没有在正确的位置滚动,它们似乎都是不正确的。

例如,如果您单击详细信息,您将滚动到投射上方。

你应该尝试:

 $('html, body').animate({ scrollTop: el.offset().top - $('header.close').height()}, 500);

滚动工作正常。如果您隐藏标题,您将看到"详细信息"完美地位于窗口顶部......

最新更新