回答編集履歴
1
実装例を追加
answer
CHANGED
@@ -1,4 +1,21 @@
|
|
1
1
|
`IntersectionObserver`を使って, ドーナツチャートがスクリーンに入った(入りきった)ことを検知してからアニメーションを開始するようすればよいでしょう.
|
2
2
|
|
3
|
+
`IntersectionObserver`の使い方の例
|
4
|
+
|
5
|
+
```JavaScript
|
6
|
+
const observer = new IntersectionObserver(
|
7
|
+
changes => changes[0].intersectionRatio >= 1 ? draw() : null,
|
8
|
+
{threshold: 1}
|
9
|
+
);
|
10
|
+
observer.observe(canvas);
|
11
|
+
function draw(){
|
12
|
+
canvas.width = canvas.height = 200;
|
13
|
+
const ctx = canvas.getContext("2d");
|
14
|
+
ctx.fillStyle = "blue";
|
15
|
+
ctx.fillRect(0, 0, 200, 200);
|
16
|
+
observer.unobserve(canvas);
|
17
|
+
}
|
18
|
+
```
|
19
|
+
|
3
20
|
参考
|
4
21
|
[https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver)
|