| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/API/Intersection_Observer_API | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2019 ..
* Some parts of this feature may have varying levels of support.
Intersection Observer API - viewport.
. . , "", , :
, Element.getBoundingClientRect(), . , .
- . , , . , . , , . , , , , .
Intersection Observer API -, ( viewport), . , , .
Observer API ; , " N%, -".
Intersection Observer API , (target) ( ) (root).
, ( null ).
, API , -, , , .
0.0 1.0, 1.0 .
-, :
var options = {
root: document.querySelector("#scrollArea"),
rootMargin: "0px",
threshold: 1.0,
};
var callback = function (entries, observer) {
/* Content excerpted, show below */
};
var observer = new IntersectionObserver(callback, options);
threshold 1.0 100% ( ) root
. . null.
root. css margin: "10px 20px 30px 40px" (top, right, bottom, left). . .
, , callback. , callback 25% : [0, 0.25, 0.5, 0.75, 1]
, , :
var target = document.querySelector("#listItem");
observer.observe(target);
, , IntersectionObserver, - callback. callback IntersectionObserverEntry :
var callback = function (entries, observer) {
entries.forEach((entry) => {
entry.time; // a DOMHightResTimeStamp indicating when the intersection occurred.
entry.rootBounds; // a DOMRectReadOnly for the intersection observer's root.
entry.boundingClientRect; // a DOMRectReadOnly for the intersection observer's target.
entry.intersectionRect; // a DOMRectReadOnly for the visible portion of the intersection observer's target.
entry.intersectionRatio; // the number for the ratio of the intersectionRect to the boundingClientRect.
entry.target; // the Element whose intersection with the intersection root changed.
entry.isIntersecting; // intersecting: true or false
});
};
, - , - , Window.requestIdleCallback().
, root, .
IntersectionObserver API Intersection Observer. observer, . observer - Document's viewport. root.
IntersectionObserverEntry . : IntersectionObserver IntersectionObserver.takeRecords().
| Specification |
|---|
| Intersection Observer # intersection-observer-interface |
IntersectionObserver and IntersectionObserverEntryThis page was last modified on 3 . 2023 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |