I would like to bring this effect of the Youtube Music app menu to my site. Basically it rolls along with the page when descending and appears again when ascending, fixedly.
Mycurrentattemptisnotsimilar,whengoingdownthepagethemenugoesupandwhenitgoesupitgoesdown,butitisnotaccordingtothescrollingmovementdone,itgoesupinstantly.Hereisanexampleoftheresultofthisattempt:
var position = $(window).scrollTop();
// should start at 0
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if(scroll > position) {
console.log('scrollDown');
if(position > 45) {
$('.a').addClass('mostra');
}
} else {
console.log('scrollUp');
$('.a').removeClass('mostra');
}
position = scroll;
});
body {
height: 2000px;
background: orange;
}
.a {
height: 50px;
width: 50px;
background-color: green;
position: fixed;
top: 0;
transition: 0.5s;
}
.mostra {
top: -50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script><divclass="a"></div>