JSFiddle - React, Tailwind, and code Playground
by Alexandru Gatea
HTML
<div class="container">
<div class="box"></div>
</div>
<div class="dummy"></div>
CSS
* {
margin: 0;
}
.container {
width: 100%;
height: 100vh;
background: #eee;
position: relative;
}
.box {
width: 100px;
height: 100px;
background: red;
opacity: 1;
position: absolute;
bottom: 0;
}
.dummy {
height: 300vh;
}
JavaScript
var container = $('.container').height();
$(window).on("scroll", function(){
scroll = $(window).scrollTop();
var stp = (scroll * 100) / container;
$('.box').css('opacity', (100 - stp) / 100);
});