check if element got scrolled to top check if element got scrolled to top jquery jquery

check if element got scrolled to top


You have to listen for the scroll event, then check each element against the currently scrolled distance, something like :

$(window).on('scroll', function() {    var scrollTop = $(this).scrollTop();    $('.background1, .background2').each(function() {        var topDistance = $(this).offset().top;        if ( (topDistance+100) < scrollTop ) {            alert( $(this).text() + ' was scrolled to the top' );        }    });});