search

Home  >  Q&A  >  body text

javascript - Is there a faster method in vue.js to scroll the current interface to a certain part?

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?

为情所困为情所困2806 days ago653

reply all(8)I'll reply

  • phpcn_u1582

    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...

    reply
    0
  • PHP中文网

    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.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新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 )

    reply
    0
  • 阿神

    阿神2017-05-18 10:47:35

    From a rough perspective, the anchor point method is definitely violent.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-18 10:47:35

    Find a native js plug-in and import it

    reply
    0
  • 阿神

    阿神2017-05-18 10:47:35

    Same question! I don’t know either

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-18 10:47:35

    https://huahua0406.github.io/...

    There is a corresponding left and right scroll below. Does it meet your requirements?

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-18 10:47:35

    vue-router2

    router has the function of simulating anchor points

    reply
    0
  • Cancelreply