-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (56 loc) · 1.88 KB
/
Copy pathscript.js
File metadata and controls
58 lines (56 loc) · 1.88 KB
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
// main 페이지 나에 대한 설명 애니메이션
const spanEl = document.querySelector("main h2 span");
const txtArr = ["Sunrin HighSchool Student", "Web Publisher", "Front-End Developer", "Web UI Designer", "UX Designer", "Back-End Developer"];
let index = 0;
let currentTxt = txtArr[index].split("");
function writeTxt() {
spanEl.textContent += currentTxt.shift();
if (currentTxt.length !== 0) {
setTimeout(writeTxt, Math.floor(Math.random() * 100));
} else {
currentTxt = spanEl.textContent.split("");
setTimeout(deleteTxt, 3000);
}
}
function deleteTxt() {
currentTxt.pop();
spanEl.textContent = currentTxt.join("");
if (currentTxt.length !== 0) {
setTimeout(deleteTxt, Math.floor(Math.random() * 100));
} else {
index = (index + 1) % txtArr.length;
currentTxt = txtArr[index].split("");
writeTxt();
}
}
writeTxt();
// 수직 스크롤 발생시 header 태그에 activate 클래스 추가 및 삭제
(function () {
const hdaerEl = document.querySelector("header");
window.addEventListener("scroll", function () {
this.requestAnimationFrame(scrollCheck);
});
function scrollCheck() {
const browserScrollY = window.scrollY ? window.scrollY : window.pageYOffset;
if (browserScrollY > 0) {
hdaerEl.classList.add("active");
} else {
hdaerEl.classList.remove("active");
}
}
})();
// 애니메이션 스크롤
(function () {
const scrollMoveEl = document.querySelectorAll("[data-animation-scroll='true']");
scrollMoveEl.forEach((el) => {
el.addEventListener("click", function () {
animationMove(this.dataset.target);
});
});
function animationMove(selector) {
const target = document.querySelector(selector);
const browserScrollY = window.pageYOffset;
const targetScrollY = target.getBoundingClientRect().top + browserScrollY;
window.scrollTo({ top: targetScrollY, behavior: "smooth" });
}
})();