js imitation anchor point jumps to the specified position of the page, using the offset() method
$(document).ready(function(){ var target_top = $("#qa5").offset().top; //$("html,body").animate({scrollTop: target_top}, 1000); // Jump with sliding effect $("html,body").scrollTop(target_top); });
jQuery:
offset():
Gets the relative offset of the matching element in the current viewport.
The returned object contains two integer properties: top and left. This method is only valid for visible elements.
position():
Gets the offset of the matching element relative to the parent element.
The returned object contains two integer properties: top and left. For accurate calculations, use pixel units on fillers, borders, and fill properties. This method is only valid for visible elements.
scrollTop() :
Method sets or returns the vertical scroll bar position of the selected element.
Tip: When the scroll bar is at the top, the position is 0.
When used for return position:
This method returns the vertical position of the scroll bar of the first matching element.
When used to set the position:
This method sets the vertical position of the scroll bars of all matching elements.
The above example of the jquery imitation anchor point jumping to the specified position on the page is all the content I share with you. I hope you can give you a reference and I hope you can support me more.