From 6a05e0a63c48c99515e7ff7be901f1104bae317c Mon Sep 17 00:00:00 2001 From: GeonilJang <52693107+takeaways@users.noreply.github.com> Date: Mon, 19 Jul 2021 12:57:12 +0900 Subject: [ko]Update Intersectionobserver example code. (#1532) --- .../api/intersectionobserver/observe/index.html | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'files/ko/web/api') diff --git a/files/ko/web/api/intersectionobserver/observe/index.html b/files/ko/web/api/intersectionobserver/observe/index.html index fdccd48325..5c10623363 100644 --- a/files/ko/web/api/intersectionobserver/observe/index.html +++ b/files/ko/web/api/intersectionobserver/observe/index.html @@ -31,7 +31,29 @@ translation_of: Web/API/IntersectionObserver/observe
<<<...>>>
+IntersectionObserver 를 등록한다
+ ++// IntersectionObserver 를 등록한다. +const io = new IntersectionObserver(entries => { + entries.forEach(entry => { + // 관찰 대상이 viewport 안에 들어온 경우 'tada' 클래스를 추가 + if (entry.intersectionRatio > 0) { + entry.target.classList.add('tada'); + } + // 그 외의 경우 'tada' 클래스 제거 + else { + entry.target.classList.remove('tada'); + } + }) +}) + +// 관찰할 대상을 선언하고, 해당 속성을 관찰시킨다. +const boxElList = document.querySelectorAll('.box'); +boxElList.forEach((el) => { + io.observe(el); +}) +