Answer the question
In order to leave comments, you need to log in
How to track the distance from the top of the page to the block?
Good afternoon, please tell me:
How can I track the distance from the top of the page to the block when scrolling.
In order for the script to connect when it reaches the block...
Now it connects only if the page is refreshed in the position where the distance is exactly or less than 1400px
const block = document.querySelector('.block');
// Получаем верхнюю координату блока относительно окна браузера
const getItemTopCoords = block.getBoundingClientRect().top;
if (getItemTopCoords + 100 <= 1400) {
const script = document.createElement('script');
script.src = './js/icon.js';
document.body.appendChild(script);
}
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