2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

how to chheck if element is visible after scrolling

I"m trying to load elements via AJAX. Some of them are only visible if you scroll down the page.
Is there any way here I can know beforehand if an element is now in the visible part of the page or not?
userimage

I hope below code snippet will give you your answer.

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));

}


Answer is