Skip to content

Instantly share code, notes, and snippets.

@gregtyler
Created August 25, 2013 21:57
Show Gist options
  • Save gregtyler/6336562 to your computer and use it in GitHub Desktop.
Save gregtyler/6336562 to your computer and use it in GitHub Desktop.
Attempt at fixing Marc with a C's little JS problem.
...
$(window).scroll(function() {
$('article').each( function(i){
var bottom_of_object = $(this).position().top;
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( $(window).scrollTop() < 2000 ) {
$('.lax').css('top', ($(window).scrollTop() * 0.25 )+'px').removeClass('active').addClass('show');
}
if( bottom_of_window > bottom_of_object && !$(this).find('img').hasClass('active') ){
animateText( $(this) );
if( $('#canvasloader-container').length == 0 ) {
$(this).append('<div id="canvasloader-container"></div>');
loader();
}
// First, assume we're not waiting for anything to load
var loading = false;
$(this).find('img').each( function(i) {
// Oh, we are waiting on something
if( !$(this).prop('complete') ) loading = true;
$(this).attr( 'src', $(this).attr('image') );
$(this).load(function () {
$(this).addClass('active');
setTimeout(function() {
$('#canvasloader-container').remove();
}, 700);
});
});
// Nothing to wait on? Take out the loader
if( !loading ) $('#canvasloader-container').remove();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment