How to scroll HTML page to given anchor?

后端 未结 17 1962
醉梦人生
醉梦人生 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:23

    jQuery("a[href^='#']").click(function(){
        jQuery('html, body').animate({
            scrollTop: jQuery( jQuery(this).attr('href') ).offset().top
        }, 1000);
        return false;
    });

提交回复
热议问题