-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
158 lines (134 loc) · 4.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const initAnimation = () => {
bounce("header h1");
bounce("footer p");
createEarth();
createHuman();
createScrollDown();
const articles = document.querySelectorAll("article");
articles.forEach((article) => {
observerAnimation("bounceScaleUp").observe(article);
});
const testimonial = document.querySelector(".testimonial");
observerAnimation("fadeInUp").observe(testimonial);
const events = document.querySelector(".events");
observerAnimation("fadeInUp").observe(events);
};
const observerAnimation = (token) => {
return new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add(token);
observer.unobserve(entry.target);
}
});
},
{
rootMargin: "0px",
threshold: 0.5,
}
);
};
const createEarth = () => {
const earthDiv = document.createElement("div");
earthDiv.className = "earth";
document.body.querySelector("section").appendChild(earthDiv);
const earth = document.querySelector(".earth");
const actionCallH2 = document.querySelector(".action-call p");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const earthRect = earth.getBoundingClientRect();
const currentTop = earthRect.top + window.scrollY;
earth.style.position = "absolute";
earth.style.top = `${currentTop + 100}px`;
} else {
earth.style.position = "fixed";
earth.style.top = "50%";
}
});
},
{
threshold: 0.1,
}
);
observer.observe(actionCallH2);
};
const createHuman = () => {
const humanDiv = document.createElement("div");
humanDiv.className = "human";
document.body.appendChild(humanDiv);
const target = document.querySelector(".action-call");
const human = document.querySelector(".human");
const earth = document.querySelector(".earth");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
window.addEventListener("scroll", handleScroll);
} else {
window.removeEventListener("scroll", handleScroll);
}
});
},
{
threshold: 0.1,
}
);
observer.observe(target);
function handleScroll() {
let newTop = -50 + window.scrollY / 12;
let newLeft = -50 + window.scrollY / 12;
human.style.top = `${newTop}%`;
human.style.left = `${newLeft}%`;
if (newTop >= 50 && newLeft >= 50) {
human.style.top = "50%";
human.style.left = "50%";
human.style.display = "none";
earth.style.backgroundImage = "url(./image/hug.png)";
window.removeEventListener("scroll", handleScroll);
}
}
};
const createScrollDown = () => {
const header = document.querySelector("header");
const scrollDown = document.createElement("div");
scrollDown.setAttribute("class", "scrollDown");
header.appendChild(scrollDown);
};
const bounce = (query) => {
const title = document.querySelector(query);
const text = title.innerText;
// 원래 텍스트를 숨겨서 접근성을 유지
const accessibleSpan = document.createElement("span");
accessibleSpan.innerText = text;
accessibleSpan.style.position = "absolute";
accessibleSpan.style.left = "-9999px";
accessibleSpan.style.width = "1px";
accessibleSpan.style.height = "1px";
title.innerHTML = ""; // 기존 내용을 삭제
title.appendChild(accessibleSpan); // 접근성을 위한 span 추가
// 애니메이션을 위한 span들 추가
text.split(" ").forEach((word, index) => {
const wordSpan = document.createElement("span");
wordSpan.className = "char"; // 애니메이션용 클래스
wordSpan.style.animationDelay = `${index * 0.1}s`;
wordSpan.textContent =
word + (index < text.split(" ").length - 1 ? " " : ""); // 공백 추가
wordSpan.setAttribute("aria-hidden", "true"); // 스크린 리더에서 이 span들을 무시하도록 설정
title.appendChild(wordSpan);
});
};
document.addEventListener("DOMContentLoaded", () => {
initAnimation();
const sections = document.querySelectorAll("section > article");
sections.forEach((section, idx) => {
const h2 = section.querySelector("h2");
if (h2) {
const id = `header-${idx}`;
h2.id = id;
section.setAttribute("aria-labelledby", id);
}
});
});