How to scroll to an element in jQuery?

后端 未结 9 1719
无人及你
无人及你 2020-11-30 19:23

I have done the following code in JavaScript to put focus on the particular element (branch1 is a element),

document.location.href=\"#branch1\";
         


        
9条回答
  •  无人及你
    2020-11-30 19:52

    Use

    $(window).scrollTop()

    It'll scroll the window to the item.

     var scrollPos =  $("#branch1").offset().top;
     $(window).scrollTop(scrollPos);
    

提交回复
热议问题