Answer the question
In order to leave comments, you need to log in
How to run script when block height changes?
The page has a floating block when scrolling and several spoilers:
<div class="container" id="js-sticky-container">
<!-- плавающий блок-->
<div class="sticky-block">
<!-- какое-то седержимое плавающего блока-->
</div>
<div class="content">
<div class="spoilers">
<!-- несколько спойлеров-->
<div class="spoilers__item">
<div class="spoilers__item-toggle"></div>
<div class="spoilers__item-content"></div>
</div>
<div class="spoilers__item">
<div class="spoilers__item-toggle"></div>
<div class="spoilers__item-content"></div>
</div>
<div class="spoilers__item">
<div class="spoilers__item-toggle"></div>
<div class="spoilers__item-content"></div>
</div>
</div>
</div>
</div>
if (document.getElementById('js-sticky-container')) {
let target = document.getElementById('js-sticky-container');
let $target = $(target);
let lastHeight = $target.height();
let observer = new MutationObserver(() => {
let newHeight = $target.height();
if (lastHeight !== newHeight) {
// тут инициализируется скрипт для плавающего блока
}
});
observer.observe(target, { attributes: true, subtree: true });
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question