jQuery move to anchor location on page load

前端 未结 3 1080
星月不相逢
星月不相逢 2021-01-30 06:22

I have a simple page setup such as:

About us content...
Header content...
3条回答
  •  一向
    一向 (楼主)
    2021-01-30 06:47

    Did you tried JQuery's scrollTo method? http://demos.flesler.com/jquery/scrollTo/

    Or you can extend JQuery and add your custom mentod:

    jQuery.fn.extend({
     scrollToMe: function () {
       var x = jQuery(this).offset().top - 100;
       jQuery('html,body').animate({scrollTop: x}, 400);
    }});
    

    Then you can call this method like:

    $("#header").scrollToMe();
    

提交回复
热议问题