The main idea of creating this function is not to use vertical scrolling, and from a click event of a button or other control to execute said function and navigate to a label <div>
or a <a>
specific label that is on the same page.
The main idea of creating this function is not to use vertical scrolling, and from a click event of a button or other control to execute said function and navigate to a label <div>
or a <a>
specific label that is on the same page.
To navigate within the same page you must use an element with id (the target) and an anchor (
<a>
) that points to said element, as follows:The target element can be any element.
To do the same thing in javascript, you can do the following: The trick here is that you set the url hash to the element's id value, just like editing it by hand in the browser's url bar.
and you use it
rnd's answer is what you want. I am going to leave an alternative with Javascript (using jQuery) in which the scroll is animated so that the target element is not jumped, but a small transition is made when moving using
animate
: