Answer the question
In order to leave comments, you need to log in
How to get the height of an element 1 time in javascript?
there is a big header and content under it. when the page scrolls to the bottom border of the header, it becomes smaller and fixed in height.
<header>шапка</header>
<section>контент</section>
var height = $('header).height();
$(window).scroll(function () {
if ($(this).scrollTop() > height ) {
$('header').addClass('stick');
$('section').css('padding-top', height );
} else {
$('header').removeClass('stick');
$('section').css('padding-top', 0);
}
});
Answer the question
In order to leave comments, you need to log in
https://jsfiddle.net/anton4ept/xk3sLhj4/
everything works fine and nothing is recalculated.
Apparently, something is not agreed.
Thank you all for pointing me in the direction of the error.
Indeed, in the wilds of scripts there was a call function, which is separately tied at this height and additionally sets it with a script (although there is a style). in the developer panel, I didn’t pay attention to the height set by js at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question