Find the vertical position of scrollbar without jQuery

后端 未结 3 599
执笔经年
执笔经年 2020-12-03 07:30

I\'m trying to find the vertical position of the scrollbar a function similar to jQuery\'s scrollTop() but with no jQuery. Are there any alternatives?

3条回答
  •  被撕碎了的回忆
    2020-12-03 07:51

    Yes, the scroll position exists within the DOM at:

    window.scrollY;  //for vertical scroll.
    

    How I found this:

    1. In Chrome, right click and select Inspect Element.
    2. Find and click the 'Show Console' button (lower-left)
    3. In the console type window.scroll to see options.

    -This is an exceptional workflow to solve a multitude of JavaScript questions.

    I see window.scrollTo(0) as an option to scroll to top.

提交回复
热议问题