質問編集履歴
2
HTMLとCSSのソースコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,6 +13,34 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
https://codepen.io/kami8ma8810/pen/KKgmQgr
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```HTML
|
20
|
+
|
21
|
+
<div class="js-trigger">
|
22
|
+
|
23
|
+
<img class="js-fadeIn" src="https://picsum.photos/seed/1/200/300" alt="">
|
24
|
+
|
25
|
+
<img class="js-fadeIn" src="https://picsum.photos/seed/2/200/300" alt="">
|
26
|
+
|
27
|
+
<img class="js-fadeIn" src="https://picsum.photos/seed/3/200/300" alt="">
|
28
|
+
|
29
|
+
</div>
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```CSS
|
36
|
+
|
37
|
+
.js-fadeIn {
|
38
|
+
|
39
|
+
opacity: 0;
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
```
|
16
44
|
|
17
45
|
|
18
46
|
|
1
jsソースコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,85 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
https://codepen.io/kami8ma8810/pen/KKgmQgr
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```JavaScript
|
20
|
+
|
21
|
+
// 監視対象
|
22
|
+
|
23
|
+
const targets = document.querySelectorAll(".js-trigger");
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
// オプション
|
28
|
+
|
29
|
+
const options = {
|
30
|
+
|
31
|
+
root: null,
|
32
|
+
|
33
|
+
rootMargin: "-50% 0px",
|
34
|
+
|
35
|
+
threshold: 0
|
36
|
+
|
37
|
+
};
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// オブジェクト生成
|
42
|
+
|
43
|
+
const observer = new IntersectionObserver(doWhenIntersect, options);
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
// targetを監視
|
48
|
+
|
49
|
+
targets.forEach((target) => {
|
50
|
+
|
51
|
+
observer.observer(target);
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
const doWhenIntersect = (entries) => {
|
58
|
+
|
59
|
+
entries.forEach((entry) => {
|
60
|
+
|
61
|
+
if (entry.isIntersecting) {
|
62
|
+
|
63
|
+
document.querySelectorAll(".js-fadeIn").forEach(function () {
|
64
|
+
|
65
|
+
gsap.fromTo(
|
66
|
+
|
67
|
+
".js-fadeIn",
|
68
|
+
|
69
|
+
{ y: 50 },
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
delay: 1,
|
74
|
+
|
75
|
+
duration: 1.5,
|
76
|
+
|
77
|
+
y: 0,
|
78
|
+
|
79
|
+
opacity: 1,
|
80
|
+
|
81
|
+
ease: "power2.out",
|
82
|
+
|
83
|
+
stagger: 0.5
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
);
|
88
|
+
|
89
|
+
});
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
});
|
94
|
+
|
95
|
+
};
|
96
|
+
|
97
|
+
```
|