jQuery Scroll To Section of Page

后端 未结 2 1584
旧巷少年郎
旧巷少年郎 2020-12-09 04:14

I\'m trying to build a new trendy one page website where I scroll to a section on the page. I want to bring the \"fixed\" header to exactly where the content is. I am usin

2条回答
  •  悲&欢浪女
    2020-12-09 04:37

    There's a plugin for that.

    Or just roll your own.

    If you need to offset the "roll your own" solution then try the following:

    $("#button").click(function() {
        var offset = 20; //Offset of 20px
    
        $('html, body').animate({
            scrollTop: $("#elementtoScrollToID").offset().top + offset
        }, 2000);
    });
    

提交回复
热议问题