Here's a solution that runs the fadeIn jQuery function after scrolling .topdiv div .topdiv .
It subtracts the viewport size from the scrollTop function to get the bottom of the scroll position, and then checks to see if its value exceeds the height of the .topdiv div plus 150 pixels or, oddly enough, how to do it fadeIn at.
Since the div must first be displayed on the page so that we scroll down somewhere, we set visibility to hidden instead of using display:none . We use fadeIn , which expects the element to start with display:none , so we .fadethisdiv div .fadethisdiv and fade it out.
Then we remove the scroll listener so that the element does not hide hidden text and fadeIn after scrolling .fadethisdiv scroll.
$(window).scroll(function () { console.log($(window).scrollTop()); var topDivHeight = $(".topdiv").height(); var viewPortSize = $(window).height(); var triggerAt = 150; var triggerHeight = (topDivHeight - viewPortSize) + triggerAt; if ($(window).scrollTop() >= triggerHeight) { $('.fadethisdiv').css('visibility', 'visible').hide().fadeIn(); $(this).off('scroll'); } });
Fiddle
Sterling graham
source share