Skip to content

Instantly share code, notes, and snippets.

@TeamBug99
Created September 22, 2021 19:10
Show Gist options
  • Save TeamBug99/cbf6d79fc2a4dd12b77c00c2ff860f55 to your computer and use it in GitHub Desktop.
Save TeamBug99/cbf6d79fc2a4dd12b77c00c2ff860f55 to your computer and use it in GitHub Desktop.
Opacity on scroll
var animation_start_pos = 0, animation_end_pos = 1000; //where you want the animation to stop
$(document).scroll(function() {
var scroll_pos = $(this).scrollTop();
var percentScrolled = parseFloat(scroll_pos/animation_end_pos);
jQuery('.people-opacity').css('opacity', percentScrolled );
});
html //
<div class="people-opacity" style="opacity: 0;"></div>
css//
.people-opacity {
background: #fff;
left: 0;
top: 0;
opacity: 0;
height: 100%;
width: 100%;
transition: .3s;
position: absolute;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment