How to scroll HTML page to given anchor?

后端 未结 17 1783
醉梦人生
醉梦人生 2020-11-22 08:55

I’d like to make the browser to scroll the page to a given anchor, just by using JavaScript.

I have specified a name or id attribute in my

17条回答
  •  渐次进展
    2020-11-22 09:10

    Great solution by jAndy, but the smooth scroll seems to be having issues working in firefox.

    Writing it this way works in Firefox as well.

    (function($) {
        $(document).ready(function() {
             $('html, body').animate({
               'scrollTop':   $('#anchorName2').offset().top
             }, 2000);
        });
    })(jQuery);
    

提交回复
热议问题