element.scrollTop // Vertical - Son los píxeles ocultos en la parte superior
element.scrollLeft // Horizontal - Son los píxeles ocultos en la parte izquierda
To get the vertical and horizontal scrolling, respectively, you have scrolled.
Clarifications:
elementit can be document.bodyif you need to know the whole page. You can compare it with:
element.offsetHeight // Son la cant de píxeles (a lo alto) que ves en el navegador.
element.offsetWidth // Son la cant de píxeles (a lo ancho) que ves en el navegador.
if you need percentages. I mean, for example: The scroll is at 50% vertically.
You can use:
To get the vertical and horizontal scrolling, respectively, you have scrolled.
Clarifications:
element
it can bedocument.body
if you need to know the whole page. You can compare it with:if you need percentages. I mean, for example: The scroll is at 50% vertically.
Yes, you can use
window.scrollY
andwindow.scrollX
to check where you stand.I show you an example with Jquery and another with pure JavaScript that does what you want:
JQUERY
pure javascript