Is there a way to know the elements that you see while scrolling?

Asked 2 years ago, Updated 2 years ago, 43 views

I'm bringing in the elements with AJAX. If you scroll down the page, you can see a certain part. Is there a way to figure out what we see here?

javascript jquery

2022-09-21 21:54

1 Answers

function isScrolledIntoView(elem)
{
    var $elem = $(elem);
    var $window = $(window);

    var docViewTop = $window.scrollTop();
    var docViewBottom = docViewTop + $window.height();

    var elemTop = $elem.offset().top;
    var elemBottom = elemTop + $elem.height();

    return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}

There's a way like this way.


2022-09-21 21:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.