Skip to content

Instantly share code, notes, and snippets.

@rleaf
Created October 6, 2019 03:45
Show Gist options
  • Save rleaf/f65df589c73f9e25383709d476e62784 to your computer and use it in GitHub Desktop.
Save rleaf/f65df589c73f9e25383709d476e62784 to your computer and use it in GitHub Desktop.
Element Fade Out on Scroll
<div class="top"><div class="title">Fade Away</div></div>
$(window).scroll(function(){
$(".top").css("opacity", 1 - $(window).scrollTop() / 250);
});
/*win.scroll(function(){
scrollPosition = win.scrollTop();
scrollRatio = 1 - scrollPosition / 300;
$(".top").css("opacity", scrollRatio);
*/
/*$(window).scroll(function(){
var scrollVar = $(window).scrollTop();
$('.top').css("opacity", 1 - scrollVar/300);
})*/
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
body {
margin: 0;
height: 1000px;
}
.top {
margin: 0;
position: relative;
width: 100%;
background-color: #aaa;
height: 300px;
opacity: 1;
text-align: center;
font-family: 'helvetica';
font-size: 80px;
font-weight: 100;
color: #fff;
}
.title {
position: absolute;
top: 60%;
left: 100px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment