For example, commonly used to return to the top, ordinary HTML pages can set the href attribute of the a tag to a certain id, and then scroll the scroll bar to that part when clicked (of course, you can also directly set the scroll bar distance. high).
My current requirement is to click different buttons in the same vue component to scroll the scroll bar to the corresponding part (the scrolling effect is optional). Directly using the above mentioned method will trigger a page jump, but if you directly set the height of the scroll bar, you have to obtain the positions one by one, which is not as simple as the former.
Asking for advice, do you have a better idea for realizing this requirement?
phpcn_u15822017-05-18 10:47:35
Element.scrollIntoView()
This is a native API of JS. After calling, the browser will scroll to the position of the target element.
https://developer.mozilla.org...
PHP中文网2017-05-18 10:47:35
If you can’t use anchor points, you can only get the scroll bar position of each part.
曾经蜡笔没有小新2017-05-18 10:47:35
Then you can only use js, as shown below, get the distance between the target element and the top of the page in the event, and then control the scroll axis:
$(window).scrollTop( $("#caaa").offset().top )
阿神2017-05-18 10:47:35
From a rough perspective, the anchor point method is definitely violent.
给我你的怀抱2017-05-18 10:47:35
https://huahua0406.github.io/...
There is a corresponding left and right scroll below. Does it meet your requirements?