Last active
October 27, 2015 20:18
-
-
Save Camwyn/7bb20449f7a8f8467967 to your computer and use it in GitHub Desktop.
Proportionate fade on scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function ( $, document ) { | |
var fadeItem = function () { | |
$('.fader').first().each( function() { | |
var $this = $(this), | |
$container = $this.parents( '.container' ), | |
height_percentage = $container.height() / $( document ).height(), | |
container_offset = $container.offset(), | |
scroll_percent = $(window).scrollTop() / ($(document).height() - $(window).height() + container_offset.top); | |
if ( $this.hasClass( 'is_stuck' )) { | |
$this.css('opacity', 1 - (scroll_percent * height_percentage * 1.5)); | |
} | |
}); | |
}; | |
var scrollDebounce = _.debounce(fadeItem, 100); | |
var scrollThrottle = _.throttle(fadeItem, 100); | |
$document.ready( function () { | |
$(window).scroll(function(){ | |
scrollDebounce(); | |
scrollThrottle(); | |
}); | |
}); | |
} )( jQuery, document ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment