平滑滚动跳转而不是滚动

时间:2014-07-15 11:08:21

标签: javascript jquery html css

我使用了CSS TRICKS的Smooth Scroll Plugin, 它工作得很好,但只有2个acoher链接而不是另一个,请看这里的演示,

LIVE DEMO

它非常适合行业和定价,但在推荐上它只是跳到了位置,固定导航也切断了部分。

<script>
$(document).ready(function () {
    $('a[href^="#"]').on('click', function (e) {
        e.preventDefault();
        var target = this.hash,
            $target = $(target);
        $('html, body').stop().animate({
            'scrollTop': $target.offset().top - 130 // - 130px (nav-height)
        }, 900, 'swing', function () {
            // Replace this with something that can be easily parsed and used by your code
            window.location.hash = '3' + target;
        });
    });
});
</script>

1 个答案:

答案 0 :(得分:1)

我在这里制作了一个小提琴手 jsfiddle.net/Thq62 /

并且它正常工作只是在链接中添加了正确的ID和哈希