How do I fade in footer on scroll?
I’ve found a few different ways to do this but interested if anyone knows a way I can do it thats more responsive to the scroll position.
I’m trying to create a parallax effect and fade the fixed footer in behind the content container on scroll.
I’ve added the desired effect with the header
jsfiddle
Javascript for header
$(document).ready(function(){
$(window).scroll(function(){
$(".intro").css("opacity", 1 - $(window).scrollTop() / $('.intro').height());
});
});
2
Answers
The logic for the footer is similar to that of the header.
You need to find the distance to the bottom of the scrolling container.
We know:
So we can come up with the simple formula:
opacity = 1 - scrollBottom / height of footer
You can try this approach for more smooth transition.
Check out this link https://codepen.io/ankitkumar507/pen/oNmWVbp to check a working example.