10 examples of 'window scrolltop' in JavaScript

Every line of 'window scrolltop' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
555export function getWindowScrollTop(rootWindow = window) {
556 let res = rootWindow.scrollY;
557
558 if (res === void 0) { // IE8-11
559 res = rootWindow.document.documentElement.scrollTop;
560 }
561
562 return res;
563}
21scrollTop (top) {
22 return this.scrollbars.scrollTop(top)
23}
95static getScrollTop() {
96 if (typeof(window.pageYOffset) === 'number') {
97 return window.pageYOffset;
98 } else if (document.body && document.body.scrollTop) {
99 return document.body.scrollTop;
100 } else if (document.documentElement && document.documentElement.scrollTop) {
101 return document.documentElement.scrollTop;
102 }
103
104 throw new Error('Unable to determine scrollTop of the window');
105}
492function findScrollTop() {
493 if (!glbl.$scrollTopNode) {
494 if (glbl.$html.scrollTop() != 0) {
495 glbl.$scrollTopNode = glbl.$html
496 } else if (glbl.$body.scrollTop() != 0) {
497 glbl.$scrollTopNode = glbl.$body
498 }
499 }
500 return (glbl.$scrollTopNode) ? glbl.$scrollTopNode.scrollTop() : 0
501}
270function documentScrollTop()
271{
272 var scrollTop = document.body.scrollTop;
273 if(document.documentElement) scrollTop = Math.max(scrollTop, document.documentElement.scrollTop);
274 return scrollTop;
275}
5function getScrollTop() {
6 return (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
7}
3export default function scrollTop(_node) {
4 const node = _node || window
5 if (node && typeof node.scrollTop !== 'undefined') {
6 return node.scrollTop
7 }
8
9 if ({}.hasOwnProperty.call(window, 'scrollY')) {
10 return window.scrollY
11 }
12 const offset = document.documentElement ?
13 document.documentElement.scrollTop :
14 0
15 return document.body.scrollTop + offset
16}
72get scrollTop() {
73 if (!this.content) { return 0; }
74
75 return this.content.scrollTop;
76}
39get scrollTop(): number {
40 return this.nativeElement.scrollTop;
41}
23static get windowScrollY() {
24 return (window.pageYOffset || window.scrollY || 0);
25}

Related snippets