This code works great for fading in/fading out whole paragraphs as the user scrolls:
$(window).scroll(function () {
$('[id^="box"]').each(function () { // <---loop the divs id starts with #box
if (($(this).offset().top - $(window).scrollTop()) < 20) { //<---mark the $(this).offset().top of current object
$(this).stop().fadeTo(100, 0); //<----fadeOut the current obj
} else {
$(this).stop().fadeTo('fast', 1); //<----fadeIn the current obj
}
});
});
But what if you want the text to fade in/fade out line by line? Has this ever been done, does anyone know?
Not sure what the use case is, but you could separate each box with span tags and change your css selector to 'span'