I am trying to combine code from a Stackoverflow question I found here with my own code. Basically when the #findme span is in the browser, I want it then to start fading in the spans one after the other from the top down (as mentioned in the last post, with the code provided by Genericrich).
The fiddle I have setup is here.
This is my js, I just can't seem to figure what I am doing wrong?
$(window).scroll(function () {
if (!spanSeen && isScrolledIntoView('#findme')) {
//What I want to happen when the span element is in view
$("span").each(function (index) {
$(this).delay(400 * index).fadeIn(300);
});
run = true;
}
});
var spanSeen = false;
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
I'm new to JS and slowly learning bit by bit, thanks in advanced.