-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (74 loc) · 1.99 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
let _accessToken = null;
let _nickName = null;
let _refreshToken = null;
let isLoged = false;
if (localStorage.getItem("accessToken") != null) {
_accessToken = localStorage.getItem("accessToken");
_nickName = localStorage.getItem("nickName");
_refreshToken = localStorage.getItem("refreshToken");
isLoged = true;
}
const authBtn = document.getElementById("auth_btn");
const authBtnContent = document.createElement("div");
authBtnContent.classList.add("nav_button");
if (isLoged) {
authBtnContent.textContent = "로그아웃";
} else {
authBtnContent.textContent = "로그인";
}
authBtn.appendChild(authBtnContent);
authBtnContent.addEventListener("click", function () {
if (isLoged) {
// 링크가 존재하면 해당 URL로 이동합니다.
localStorage.removeItem("accessToken");
localStorage.removeItem("nickName");
localStorage.removeItem("refreshToken");
location.reload(true);
} else {
window.location.href = "auth/auth.html";
}
});
const buttons = document.querySelectorAll(".crs-btn");
const prevBtn = buttons.item(0);
const nextBtn = buttons.item(1);
const backgroundWrapper = document.querySelector(".background-wrapper");
let idx = 0;
prevBtn.addEventListener("click", () => {
PrevCRS(idx);
});
nextBtn.addEventListener("click", () => {
NextCRS(idx);
});
// 1000 밀리초(1초)마다 logMessage 함수를 호출
let intervalId = setInterval(iterIndex, 3000);
function NextCRS() {
idx++;
if (idx > 3) {
idx = 3;
return false;
}
backgroundWrapper.style.transform = `translate(-${25 * idx}%)`;
clearInterval(intervalId);
intervalId = setInterval(iterIndex, 3000);
return true;
}
function PrevCRS() {
idx--;
if (idx < 0) {
idx = 0;
return true;
}
backgroundWrapper.style.transform = `translate(-${25 * idx}%)`;
clearInterval(intervalId);
intervalId = setInterval(iterIndex, 3000);
return false;
}
let next = true;
function iterIndex() {
idx % 4;
if (next) {
next = NextCRS();
} else {
next = PrevCRS();
}
}