Notice: file_put_contents(): Write of 5663 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 12288 of 17951 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
Node.JS [ru] | Серверный JavaScript@we_use_js P.4279
WE_USE_JS Telegram 4279
⚙️ Что такое Intersection Observer в JavaScript и зачем он используется?

Intersection Observer — это API, которое позволяет отслеживать, когда элемент входит или выходит из области видимости (viewport). Оно полезно для оптимизации ленивой загрузки изображений, бесконечной прокрутки или анимаций при прокрутке.

➡️ Пример:

// Целевой элемент для наблюдения
const target = document.querySelector('.observe-me');

// Callback-функция для обработки пересечений
const observerCallback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
console.log('Элемент видим:', entry.target);
observer.unobserve(entry.target); // Останавливаем наблюдение
}
});
};

// Настройки наблюдателя
const observerOptions = {
root: null, // Вся область видимости
threshold: 0.5 // 50% видимости элемента
};

// Создаем наблюдатель
const observer = new IntersectionObserver(observerCallback, observerOptions);

// Начинаем наблюдение за элементом
observer.observe(target);


🗣️ В этом примере API отслеживает, когда .observe-me становится видимым на 50%. Intersection Observer делает прокрутку более производительной, так как избавляет от необходимости использовать события scroll.


🖥 Подробнее тут
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥6👍3



tgoop.com/we_use_js/4279
Create:
Last Update:

⚙️ Что такое Intersection Observer в JavaScript и зачем он используется?

Intersection Observer — это API, которое позволяет отслеживать, когда элемент входит или выходит из области видимости (viewport). Оно полезно для оптимизации ленивой загрузки изображений, бесконечной прокрутки или анимаций при прокрутке.

➡️ Пример:

// Целевой элемент для наблюдения
const target = document.querySelector('.observe-me');

// Callback-функция для обработки пересечений
const observerCallback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
console.log('Элемент видим:', entry.target);
observer.unobserve(entry.target); // Останавливаем наблюдение
}
});
};

// Настройки наблюдателя
const observerOptions = {
root: null, // Вся область видимости
threshold: 0.5 // 50% видимости элемента
};

// Создаем наблюдатель
const observer = new IntersectionObserver(observerCallback, observerOptions);

// Начинаем наблюдение за элементом
observer.observe(target);


🗣️ В этом примере API отслеживает, когда .observe-me становится видимым на 50%. Intersection Observer делает прокрутку более производительной, так как избавляет от необходимости использовать события scroll.


🖥 Подробнее тут

BY Node.JS [ru] | Серверный JavaScript


Share with your friend now:
tgoop.com/we_use_js/4279

View MORE
Open in Telegram


Telegram News

Date: |

You can invite up to 200 people from your contacts to join your channel as the next step. Select the users you want to add and click “Invite.” You can skip this step altogether. On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of “doxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. Other crimes that the SUCK Channel incited under Ng’s watch included using corrosive chemicals to make explosives and causing grievous bodily harm with intent. The court also found Ng responsible for calling on people to assist protesters who clashed violently with police at several universities in November 2019. How to create a business channel on Telegram? (Tutorial) Matt Hussey, editorial director of NEAR Protocol (and former editor-in-chief of Decrypt) responded to the news of the Telegram group with “#meIRL.”
from us


Telegram Node.JS [ru] | Серверный JavaScript
FROM American