0
I have a div (Fixed) that appears when the page is scrolled down and reappears when the page is scrolled up. I need it to just disappear (when rolling down) from the body’s 45px. That is, while the user only rolls 44.9px it does not disappear and, from that, yes.
Here my example:
var position = $(window).scrollTop();
// should start at 0
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if(scroll > position) {
console.log('scrollDown');
$('.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.4/jquery.min.js"></script>
<div class="a"></div>
Interesting, I didn’t know...
– Thiago Soubra
but I don’t understand how it works very well. how/where to determine which style changes when rolling?
– Thiago Soubra
Interesting. I didn’t know it either. But it doesn’t compete with the question: "I need it to just disappear (when rolling down) from the body’s 45px. That is, while the user only rolls 44.9px it does not disappear and, from that, yes."... That way she doesn’t "disappear"...
– LipESprY