Answer the question
In order to leave comments, you need to log in
CSS actions for nested .sticky-top element?
Hello, question about the sticky-top class (bootstrap4), aka position: sticky, I would like to change the size of the logo to css when the sticky-top class is active.
works:
.sticky-top {
top: 32px; //отступ появляется только когда элемент прилипает
}
.sticky-top .navbar .navbar-brand {
min-width: 130px; //размер установлен вне зависимости от того прилипший ли навбар
top: 20px; // то же с высотой
}
Answer the question
In order to leave comments, you need to log in
Add another class when moving down and remove it when returning up, and already hang the size of the logo and other styles to this class
$(window).on('scroll', function (event) {
var scrollValue = $(window).scrollTop();
if (scrollValue > 150) {
$('.navbar').addClass('newclass');
} else{
$('.navbar').removeClass(newclass');
}
});
So far I had to solve the problem like this:
var $navBar = $('.sticky-top');
var navPos = $navBar.offset().top;
$(window).scroll(function() {
var scrollPos = $(this).scrollTop();
if (scrollPos >= navPos) {
$navBar.addClass('fixed');
} else {
$navBar.removeClass('fixed');
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question