0

I'm looking to find the HTML element or content which occupies the pixel position on a page. I am using currently using jQuery to find the scrollTop() position:

$(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
    console.log(scroll);
    // Do something 
});

to understand the $(window).scrollTop() position, but I'd like to know what occupies the space. E.g., if a user scrolls to '300', what HTML element or content is there?

Scrolltop code from How to detect scroll position of page using jQuery

Community
  • 1
  • 1
Hemmed
  • 35
  • 1
  • 5

1 Answers1

0
function checkElement(el){
    var windowHeight = $(window).height();
    var scroll = $(window).scrollTop();

    var elementPosition = el.height() + el.position().top;
    if (elementPosition > scroll &&  elementPosition < windowHeight + scroll){
        return true;
    }
    return false;
}
Helen Fung
  • 50
  • 6