Reputation: 12487
This is my code: http://jsfiddle.net/spadez/Fq5K4/
I want to make it so that as the user scrolls down the page, the image in the top section turns black the more i scroll down so that that whole block is completely black. This technique can be seen here:
http://www.metalabdesign.com/work/
The closest bit of code I could find is like this: http://jsfiddle.net/HsRpT/6/:
$(window).scroll(function() {
var el = $('.block');
var offset = el.offset();
var opacity = ( (offset.top - el.height() ) / 100 ) * -1;
$('.block').css('opacity', opacity );
});
Upvotes: 3
Views: 897
Reputation: 318182
You'd do that like this :
$(window).on('scroll', function() {
$('.block').css('opacity', function() {
return 1 - ($(window).scrollTop() / $(this).outerHeight());
});
});
Upvotes: 2