Reputation: 263
Why is the clientY equal to undefined in the code below?
window.addEventListener('scroll', e => {
console.log(document.querySelector('section').clientY);
});
<div>qwq</div>
<div>wq</div>
<div>ad</div>
<div>qw</div>
<div>qwq</div>
<div>wq</div>
<div>ad</div>
<section>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptatibus temporibus eius mollitia cupiditate earum ex eaque ut laudantium magni tempore vel, nulla libero, animi tenetur accusamus consequuntur obcaecati ipsa quibusdam?Lorem ipsum, dolor sit
amet consectetur adipisicing elit. Provident, facilis fuga at voluptatibus laudantium magni! Id aspernatur quaerat consequatur. Eligendi officiis voluptas, voluptates consequatur accusamus cum distinctio? At, doloribus ipsa!</section>
upd:
ok, i`ve trying make event listener which the when scrolling, body checks the distance from the top of the window to the element - example. Click left side panel link and you will understand what I mean.
Upvotes: 0
Views: 574
Reputation: 81
I'm guessing that you trying to find the offset of the <section>
from the top of scrollable element (window
in your case) after scrolling.
So, to do that you can try
document.querySelector('section').getBoundingClientRect().top
Upvotes: 2