Scroll to specific div on page load

后端 未结 3 679
长发绾君心
长发绾君心 2020-12-24 02:34

I\'m trying to figure out how get the page automaticlly scroll to a specific div when the page has loaded. I have tried using the jQuery scroll function, but cant get it to

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 02:58

    You can do this using the .animate() method:

    $(document).ready(function () {
        // Handler for .ready() called.
        $('html, body').animate({
            scrollTop: $('#what').offset().top
        }, 'slow');
    });
    
    • This will smooth scroll to the div with ID what

    FIDDLE

提交回复
热议问题