-1
I created a menu that, depending on the size of the screen, behaves like a fixed menu. However, when resizing the screen to normal size, the menu keeps adding the class to fix it, when it wasn’t supposed to happen.
This is the menu (which is inside a sidebar):
.bottom{
bottom: 90px;
padding: 15px;
height: 45px;
box-shadow: 0 4px 2px -2px #f5f5f5;
}
This is the class used to define it as fixed:
.glue{
position: fixed;
width: 100%;
z-index: 9;
top: 0;
}
This is the code I used to fix depending on the screen size. For screens smaller than 1024px, it is fixed after rolling 410px and for screens larger than 1024px and smaller than or equal to 1125px, after 500px.
$(window).resize(function(){
var ww = $(window).width();
if (ww <= 1024) {
$(window).scroll(function(){
var scroll = $(window).scrollTop();
if (scroll >= 410) {
$('.bottom').addClass("glue");
} else {
$('.bottom').removeClass("glue");
}
});
} if ((ww > 1024) && (ww <= 1125)) {
$(window).scroll(function(){
var scroll = $(window).scrollTop();
if (scroll >= 500) {
$('.bottom').addClass("glue");
} else {
$('.bottom').removeClass("glue");
}
});
}
});
I reproduced this problem in a separate blog, since I couldn’t get it from the editor here
It would not be better to use media queries ?
– Gato de Schrödinger