teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

例追加

2020/02/07 08:41

投稿

x_x
x_x

スコア13749

answer CHANGED
@@ -8,4 +8,18 @@
8
8
  }
9
9
  });
10
10
  ```
11
- [https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint](https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint)
11
+ [https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint](https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint)
12
+
13
+ IntersectionObserver の例
14
+ ```jQuery
15
+ const observer = new IntersectionObserver((entries, observer) => {
16
+ const entry = entries.find(a => a.isIntersecting);
17
+ if (entry) {
18
+ const id = entry.target.id;
19
+ $('nav li a[href="#' + id + '"]').closest('li').addClass('selected').siblings().removeClass('selected');
20
+ }
21
+ }, { rootMargin: '-50%' });
22
+ $('section[id]').each((index, element) => observer.observe(element));
23
+ ```
24
+
25
+ [https://developer.mozilla.org/ja/docs/Web/API/Intersection_Observer_API](https://developer.mozilla.org/ja/docs/Web/API/Intersection_Observer_API)

1

不要個所削除

2020/02/07 08:41

投稿

x_x
x_x

スコア13749

answer CHANGED
@@ -8,6 +8,4 @@
8
8
  }
9
9
  });
10
10
  ```
11
- [https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint](https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint)
11
+ [https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint](https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint)
12
-
13
- elementFromPoint