Hi, I'm making a function with scroll.
When the scroll goes down 150 I show a banner at the bottom and when I go up the scroll to the top it hides again.
$(function() {
// esta parte es la que controla cuando se mueve el scroll y ejecuta una función
$(document).scroll(function() {
// aca se pregunta si el scroll se movio de pa bajo.
if ($(this).scrollTop() < 150) {
// esta parte cambia el atributo "src" de la etiqueta "img"
$('.barraTella').css("bottom","-200px");
$('.barraTella').css("transition","1s");
}
if ($(this).scrollTop() > 150) {
$('.barraTella').css("bottom","0px");
$('.barraTella').css("transition","1s");
}
});
});
But I also added a button to be able to close that banner.
$( "#closeLlama" ).click(function() {
$('#barraTella').css("bottom","-200px");
$('#barraTella').css("transition","1s");
});
The problem is that, if I close it, and I scroll again, it is shown again.
What I need is: that until I go back up all the way and do those 150 down again, it doesn't show up again.
Any suggestion?
You can use one
var
so that when you click, the value of that variable changes:and in
if ($(this).scrollTop() > 150 && buttonClicked==false)
it you check that that variable continues as it was (that is, it has not been clicked yet). If in the click event you change the variable it will no longer enter thereTo finish, you reset the variable when the scroll returns to the top:
Snippet: