From 321e9f39e87510a6317a1f9c5c993523294da4a5 Mon Sep 17 00:00:00 2001 From: alattalatta Date: Sun, 28 Nov 2021 21:47:30 +0900 Subject: Rewrite and add IntersectionObserver methods --- .../web/api/intersectionobserver/observe/index.md | 99 +++++++++------------- 1 file changed, 42 insertions(+), 57 deletions(-) (limited to 'files/ko/web/api/intersectionobserver/observe') diff --git a/files/ko/web/api/intersectionobserver/observe/index.md b/files/ko/web/api/intersectionobserver/observe/index.md index 5c10623363..942c42af61 100644 --- a/files/ko/web/api/intersectionobserver/observe/index.md +++ b/files/ko/web/api/intersectionobserver/observe/index.md @@ -1,85 +1,70 @@ --- title: IntersectionObserver.observe() slug: Web/API/IntersectionObserver/observe +tags: + - API + - Intersection Observer + - Intersection Observer API + - IntersectionObserver + - Method + - Reference +browser-compat: api.IntersectionObserver.observe translation_of: Web/API/IntersectionObserver/observe --- -
{{APIRef("Intersection Observer API")}}{{SeeCompatTable}}
+{{APIRef("Intersection Observer API")}} -

The {{domxref("IntersectionObserver")}} observe() 메서드는 IntersectionObserver 객체가 관찰할 엘리먼트 목록에 단일 엘리먼트를 추가합니다. 하나의 옵저버 객체는 단일한 threshold와 root를 가지지만 복수의 타겟 엘리먼트의 가시성 변화를 관찰할 수 있습니다. 만일 엘리먼트 관찰을 중지하고 싶다면 {{domxref("IntersectionObserver.unobserve()")}} 메서드를 호출하세요.

+{{domxref("IntersectionObserver")}}의 **`observe()`** 메서드는 `IntersectionObserver`의 주시 대상 목록에 요소를 추가합니다. 하나의 감지기는 하나의 루트와 하나의 역치 목록만 가질 수 있지만, 동시에 여러 요소를 주시할 수 있습니다. -

특정 엘리먼트의 가시성이 다른 옵저버의 가시성 threshold와 교차할 때({{domxref("IntersectionObserver.thresholds")}} 참조), 옵저버 콜백은 발생한 교차성 변경을 알리는 {{domxref("IntersectionObserverEntry")}} 객체와 함께 실행됩니다.

+요소의 주시를 중단하려면 {{domxref("IntersectionObserver.unobserve()")}}를 호출하세요. -

노트. 이 디자인은 복수 엘리먼트의 교차성 변경이 하나의 콜백 실행을 통해 처리되는 것을 허용합니다.

+지정한 주시 대상 요소의 가시성 비율이 감지기의 역치({{domxref("IntersectionObserver.thresholds")}})를 통과하는 순간 감지기 콜백이 호출됩니다. 이때 역치를 통과한 요소를 나타내는 {{domxref("IntersectionObserverEntry")}}의 배열을 콜백 매개변수로 제공합니다. 이런 구조 덕분에 한 번의 콜백 호출만으로 많은 요소의 가시성 변화를 한 번에 처리할 수 있습니다. -

문법

+## 구문 -
IntersectionObserver.observe(targetElement);
+```js +IntersectionObserver.observe(targetElement); +``` +### 매개변수 -

Parameters

+- `targetElement` + - : 루트 내에서의 가시성 변화를 감지할 {{domxref("element")}}입니다. 루트 요소의 자손이어야 합니다. 루트가 현재 문서의 뷰포트일 경우 이 요소도 문서 내에 위치해야 합니다. -
-
targetElement
-
가시성이 감시될 root 내부의 {{domxref("element")}}. 해당 엘리먼트는 루트 엘리먼트의 자손 노드여야 합니다(혹은 현재 root가 document의 viewport일 때는 현재 document 내부의 엘리먼트여야 합니다).
-
+### 반환 값 -

Return value

+`undefined`. -

undefined.

+## 예제 -
-
- -

Examples

- -

IntersectionObserver 를 등록한다

- -
-// IntersectionObserver 를 등록한다.
+```js
+// IntersectionObserver 등록
 const io = new IntersectionObserver(entries => {
   entries.forEach(entry => {
-    // 관찰 대상이 viewport 안에 들어온 경우 'tada' 클래스를 추가
+    // 주시 대상이 뷰포트 안으로 들어오면 active 클래스 추가
     if (entry.intersectionRatio > 0) {
-      entry.target.classList.add('tada');
+      entry.target.classList.add('active');
     }
-    // 그 외의 경우 'tada' 클래스 제거
+    // 아니면 active 클래스 제거
     else {
-      entry.target.classList.remove('tada');
+      entry.target.classList.remove('active');
     }
   })
 })
 
-// 관찰할 대상을 선언하고, 해당 속성을 관찰시킨다.
+// 주시 대상 선언, 주시 시작
 const boxElList = document.querySelectorAll('.box');
 boxElList.forEach((el) => {
   io.observe(el);
 })
-
- -

Specifications

- - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('IntersectionObserver','#dom-intersectionobserver-observe','IntersectionObserver.observe()')}}{{Spec2('IntersectionObserver')}}Initial definition.
- -
-

Browser compatibility

- -

{{Compat("api.IntersectionObserver.observe")}}

-
- -

See also

- - +``` + +## 명세 + +{{Specifications}} + +## 브라우저 호환성 + +{{Compat}} + +## 같이 보기 + +- {{domxref("IntersectionObserver.unobserve()")}} -- cgit v1.2.3-54-g00ecf