Home

documentbodyscrollTop

Document.body.scrollTop is a property of the body element that reports the vertical scroll offset of the document in pixels. It indicates how far the page has been scrolled from the top and can be written to in some browsers to influence the scroll position.

Cross-browser behavior for the document’s scroll position is inconsistent. In standards-compliant mode, many browsers reflect the

To reliably obtain the vertical offset across browsers, a common approach is to use a fallback chain

For changing the scroll position, the preferred method is to use scrolling APIs rather than assigning to

In modern web development, window.pageYOffset and window.scrollTo (or the newer scrollTo options) are the standard tools

See also: pageYOffset, scrollTop, documentElement, window.scrollTo.

---

current
vertical
offset
on
document.documentElement,
while
in
quirks
mode
or
older
implementations,
document.body.scrollTop
may
hold
the
value.
As
a
result,
reading
document.body.scrollTop
alone
can
yield
different
results
depending
on
the
browser
and
document
mode.
such
as:
window.pageYOffset
||
document.documentElement.scrollTop
||
document.body.scrollTop
||
0.
This
captures
the
value
from
the
most
consistently
supported
sources.
document.body.scrollTop.
Methods
such
as
window.scrollTo(0,
value)
or
window.scrollTo({
top:
value
})
directly
set
the
vertical
position.
While
assigning
document.body.scrollTop
=
value
may
work
in
some
environments,
it
is
not
guaranteed
to
function
uniformly
across
all
browsers.
for
reading
and
manipulating
scroll
position.
document.body.scrollTop
remains
a
legacy
artifact
that
may
be
encountered
in
older
code
or
compatibility
layers.