-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
165 lines (140 loc) ยท 8.29 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
159
160
161
162
163
164
function getCityData(city) {
fetch(`http://localhost:8000/data/${city}`) // ํด๋น ์ฃผ์์ api๋ฅผ ๋ถ๋ฌ์ด
.then((response) => response.json()) // ๋ถ๋ฌ์จ api ๊ฐ์ response๋ก ๋ฐ๊ณ response๊ฐ์ json์ผ๋ก ๋ฆฌํด ํ๋ค.
.then((data) => { //๊ทธ ๊ฐ์ด data๋ผ๋ ๋ณ์์ json array ํํ๋ก ๋ค์ด๊ฐ
let num = 1;
data.forEach(element => { //๊ฐ์ ธ์จ ๊ฐ์ ๋ชจ๋ ๊ฐ์ ๊ฐ์ ธ์ค๊ธฐ ์ํด forEach๋ฌธ์ผ๋ก ๋ชจ๋ ์์๋ฅผ ๋ฐ๋ณตํด ๊ฐ์ ธ์ด
const list = document.getElementById('listElement') // ์ฝ์ด์จ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ ๋ฆฌ์คํธ์ ์์ด๋๋ฅผ ๊ฐ์ ธ์ด
list.insertAdjacentHTML('beforeend', `
<div class="restaurant-wrapper" onclick = "window.open('https://www.mangoplate.com/search/${element.๋ช
์}')">
<p class="find-restaurant">'${element.๋ช
์}' ์ฃผ๋ณ ๋ง์ง ํ์ธํ๊ธฐโ</p>
</div>
<li class="tourist-attraction-list">
<div class="list-number-wrapper">
<div class="list-number">${num}</div>
</div>
<div class="tourist-attraction-container">
<p class="tourist-attraction-ID">${element.๋ช
์}</p>
<p class="tourist-attraction-StarRating">โญ${element.๋ณ์ }</p>
</div>
</li>
<div class="solid-line"></div>
`); // ์์ด๋๋ก ๊ฐ์ ธ์จ ๊ฐ์ html ๋ฌธ์ผ๋ก ๋ฐ๋ณตํด์ ๋ค์ ์ถ๊ฐํจ
num++; // ์์ ์ฆ๊ฐ
});
AligningListNumberSpacing();
});
}
function loadCity(city) {
let tags = {
'seoul': 'tagSeoul',
'gyeonggi': 'tagGyeonggi',
'sokcho': 'tagSokcho',
'busan': 'tagBusan'
}
document.getElementById('listElement').innerHTML = '';
getCityData(city);
changeTag(tags[city]);
}
function changeTag(selectedTag) {
let tagList = ['tagSeoul', 'tagGyeonggi', 'tagSokcho', 'tagBusan'];
tagList = tagList.filter(tag => tag !== selectedTag)
document.getElementById(selectedTag).style.backgroundColor = "#186ADE";
document.getElementById(selectedTag).style.color = "#fff";
document.getElementById(selectedTag).style.fontWeight = "700";
for (let tag of tagList) {
document.getElementById(tag).style.backgroundColor = "#DCE3E8";
document.getElementById(tag).style.color = "#000";
document.getElementById(tag).style.fontWeight = "normal";
}
}
loadCity('seoul');
const titleSeoul = document.getElementById('seoul');
const titleGyeonggi = document.getElementById('gyeonggi');
const titleSokcho = document.getElementById('sokcho');
const titleBusan = document.getElementById('busan');
let cityList = [titleSeoul, titleGyeonggi, titleSokcho, titleBusan]
let imgList = ["url('img/photo-1628008335819-7175b35fa4f5.avif')", "url('img/photo-1598523318933-fa99cf949897.avif')", "url('img/photo-1603031682537-ea6729c9d1bc.avif')", "url('img/photo-1541055575455-df3a497caa48.avif')"];
function onTitle(index) {
cityList[index].style.color = "#fff";
cityList[index].style.zIndex = "999";
document.getElementById('mainImage').style.backgroundImage = imgList[index];
// document.getElementById('img-container').style.backgroundImage = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCA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ExsmP9AxbDTc9JwgneAT5vTiUSm1E7BSflSt3bfa1tv8Di3R8n3Af7MNWzs49hmauE2wP+ttrq+AsWpFG2awvsuOqbipWHgtuvuaAE+A1Z/7gC9hesnr+7wqCwG8c5yAg3AL1fm8T9AZtp/bbJGwl1pNrE7RuOX7PeMRUERVaPpEs+yqeoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==')";
document.getElementById('black').style.opacity = 0;
}
function offTitle(index) {
cityList[index].style.color = "rgba(0, 0, 0, 0)";
document.getElementById('black').style.opacity = 1;
// document.getElementById('black').style.background = "#000";
}
function sleep(ms) {
return new Promise((r) => setTimeout(r, ms));
}
let index = 0;
function check_index_and_reset() {
if (index >= 3) {
index = 0;
} else {
index += 1;
}
}
setInterval(() => {
onTitle(index);
sleep(3500)
.then(() => offTitle(index))
.then(() => check_index_and_reset())
}, 6000);
const className = document.querySelectorAll('.developer-name');
/**
* githubID์ ๋ฐ๋ฅธ githubํ๋กํ์ ์ ํญ์์ ๋ณผ ์ ์๊ฒ ํจ
* @param {string} githubID github์์ด๋
*/
function linkGithub(githubID) {
window.open(`https://github.com/${githubID}`);
}
[].forEach.call(className, (element) => {
element.addEventListener('click', () => {
let className = element.classList[1];
linkGithub(className === 'developer-name-jaewon' ? 'wodnjse' : 'baekinwon');
})
})
const listElement = document.getElementById('listElement');
let isVisible = false;
addEventListener('scroll', () => {
let viewportTop = Math.floor(listElement.getBoundingClientRect().top);
if(viewportTop < 0) {
if(isVisible) return;
const test = document.getElementsByClassName('main-module-container')[0];
test.insertAdjacentHTML('beforeend', `
<div class="floating-btn" id="floatingButton">
<span class="material-symbols-outlined"></span>
<span class="btn-text">์๋ก ์ฌ๋ผ๊ฐ๊ธฐ</span>
</div>
`)
const scrollTop = document.getElementById('floatingButton');
scrollTop.addEventListener('click', () => {
const scrollPosition = document.getElementById('touristAttraction').offsetTop; // offsetTop: ํ๋ฉด ์ต์๋จ์ผ๋ก๋ถํฐ์ ํฝ์
๊ฐ
// ํ๋ฉด ์ต์๋จ์์๋ถํฐ 1783px - 100px = ์คํฌ๋กค ์ ์๋จ์ 100px ์ฌ๋ฐฑ ์ฃผ๊ธฐ
window.scrollTo({top: scrollPosition - 100, behavior: 'smooth'}); // behavior: smooth = ๋ถ๋๋ฌ์ด ์คํฌ๋กค ํจ๊ณผ
});
isVisible = true;
} else {
if(!isVisible) return;
document.getElementById('floatingButton').remove();
isVisible = false;
}
})
/**
* ๋ฆฌ์คํธ ์ซ์์ width๊ฐ ์ผ์ ํ์ง ์์ ์ฌํ์ง๋ช
๊ฐ๊ฒฉ์ด ๋ง์ถฐ์ง์ง ์๋ ์ค๋ฅ
* .list-number์ width๋ฅผ ์ผ์ ํ๊ฒ ์ค์ ํ์ฌ ๊ฐ๊ฒฉ ๋ง์ถค
* @constructor
*/
function AligningListNumberSpacing() {
let listNumber = document.querySelectorAll('.list-number');
listNumber.forEach(nodeIndex => {
// ๋ฆฌ์คํธ ์ซ์์ width๊ฐ 25px ๋ฏธ๋ง์ด๋ฉด => width: 20px
if (nodeIndex.clientWidth < 25) nodeIndex.style.width = '20px';
// ๊ทธ ์ธ(width๊ฐ 25px ์ด์) => width: 32px
else nodeIndex.style.width = '32px';
});
}