T
T
thehighhomie2015-09-27 07:58:37
JavaScript
thehighhomie, 2015-09-27 07:58:37

Fix document.document.body.scrollTop issue?

How can the problem of document.body.scrollTop and document.documentElement.scrollTop be solved?
Of course, you can create a variable and assign Math.max( document.body.scrollTop, document.documentElement.scrollTop ) to it, only if, for example, the header has a navigation in which, when you click on the link, the page scrolls to the desired section, and in any case, at least document .body.scrollTop, even though document.documentElement.scrollTop is still equal to 0(. You can of course use hashes, but in my case a hash is not needed.
How can I get around this? Preferably without jquery and the like, I want to know how such moments can be solved.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-09-27
@thehighhomie

Are you talking about errors in Opera, Chrome and Safari?
If yes, then there is no need to use them document.body.scrollTop, you can simply refer to window.pageYOffset. But where this property is not present, it works anywaydocument.documentElement.scrollTop

var cur_y = "pageYOffset" in window ? 
  window.pageYOffset : document.documentElement.scrollTop;

And if the point is that it pageYOffsetcannot be changed, then there are methods scrollToand scrollBy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question