-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
182 lines (152 loc) · 4.61 KB
/
Copy pathmain.js
File metadata and controls
182 lines (152 loc) · 4.61 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import {
getFestival,
uhaRenderList,
uhaHandleMouseEnter,
uhaHandleMouseLeave,
createFestivalInfo,
filterFestivals,
noResultsRender,
} from "./js/index.js";
import { config } from "./js/data/apikey.js";
import {
addMarkers,
deleteMarkers,
initMap,
isDefaultMarker,
isFocusMarker,
setMapCenter,
} from "./js/components/map.js";
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
const toggle = $(".nav_btn");
const nav = $(".nav");
const gnb = $(".gnb");
const stripes = $(".stripes");
const links = $$(".nav a");
let markers = {};
const map = initMap();
setMapCenter(map);
markers = addMarkers(map);
toggle.addEventListener("click", () => {
nav.classList.toggle("visible");
toggle.classList.toggle("visible");
stripes.classList.toggle("visible");
gnb.classList.toggle("hidden");
});
document.addEventListener("click", (e) => {
if (e.target.closest(".nav a")) {
nav.classList.remove("visible");
toggle.classList.remove("visible");
stripes.classList.remove("visible");
gnb.classList.remove("hidden");
}
});
const controllerBtn = $(".video_controller a");
const video = $(".main_video");
function controllerBtnHandler(buttonState) {
if (buttonState === "pause") {
controllerBtn.setAttribute("data-play", "pause");
controllerBtn.classList.add("pause");
} else if (buttonState === "play") {
controllerBtn.setAttribute("data-play", "play");
controllerBtn.classList.remove("pause");
}
}
controllerBtn.addEventListener("click", function () {
const dataPlay = this.getAttribute("data-play");
if (dataPlay === "pause") {
video.pause();
controllerBtnHandler("play");
} else if (dataPlay === "play") {
video.play().catch((e) => console.error(e));
controllerBtnHandler("pause");
}
});
window.addEventListener("scroll", () => {
const scrollY = window.scrollY || window.pageYOffset;
if (scrollY > 800) {
gnb.classList.add("dark");
toggle.classList.add("dark");
} else {
gnb.classList.remove("dark");
toggle.classList.remove("dark");
}
});
const split = new SplitText(".main_visual01 h2", { type: "chars" });
gsap.from(split.chars, {
opacity: 0,
y: 30,
stagger: 0.1,
delay: 0.3,
ease: "back(2)",
immediateRender: false,
});
gsap.registerPlugin(ScrollTrigger);
const visualWrapper = $(".main_visual_wrapper");
const visuals = $$(".main_visual");
function setWrapperWidth() {
const wrapperWidth = visuals.length * window.innerWidth;
visualWrapper.style.width = wrapperWidth + "px";
gsap.set(visualWrapper, { x: 0 });
ScrollTrigger.getAll().forEach(trigger => trigger.kill());
gsap.to(visualWrapper, {
x: () => -wrapperWidth + window.innerWidth,
ease: "none",
scrollTrigger: {
trigger: ".section01",
start: "top top",
end: () => "+=" + (wrapperWidth - window.innerWidth),
scrub: 1,
pin: true,
invalidateOnRefresh: true,
},
});
ScrollTrigger.refresh();
}
setWrapperWidth();
window.addEventListener("resize", () => {
setWrapperWidth();
});
let festivalList = getFestival();
const uhaUl = document.querySelector(".uhaUl");
const imgNode = document.querySelector(".map-block");
const infoNode = document.querySelector(".fillter-list");
const searchButton = document.querySelector(".search-button");
uhaRenderList(festivalList, uhaUl);
const uhaButtons = document.querySelectorAll("li button");
uhaButtons.forEach((uhaButton) => {
uhaButton.addEventListener("mouseenter", uhaHandleMouseEnter);
uhaButton.addEventListener("mouseleave", uhaHandleMouseLeave);
});
searchButton.addEventListener("click", () => {
festivalList = filterFestivals();
if(festivalList.length === 0){ // 필터된 축제가 없으면?
noResultsRender() // 검색 결과 없을때 랜더되는 컴포넌트.
return; // 검색 결과가 없으므로 종료.
}
uhaUl.innerHTML = "";
uhaRenderList(festivalList, uhaUl);
gsap.from(".uhaLi", {
opacity: 0,
y: 30,
stagger: 0.1,
duration: 0.5,
ease: "power2.out",
});
const uhaButtons = document.querySelectorAll("li button");
uhaButtons.forEach((uhaButton) => {
uhaButton.addEventListener("mouseenter", uhaHandleMouseEnter);
uhaButton.addEventListener("mouseleave", uhaHandleMouseLeave);
});
markers = deleteMarkers();
markers = addMarkers(map, festivalList);
});
function test(e) {
console.log("test 함수 호출");
const target = e.target.closest(".uhaLi button");
const targetId = target.id;
createFestivalInfo(targetId, infoNode, imgNode);
uhaUl.classList.add("display-none");
imgNode.classList.add("display-none");
}
uhaUl.addEventListener("click", test);