-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (28 loc) · 832 Bytes
/
script.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
const topBtn = document.getElementById('top-btn')
const menuBtn = document.getElementById('menu-btn')
const menu = document.getElementById('menu')
const projects = document.querySelectorAll('.project')
const urls = ['calc_project/index.html', 'snake_game/index.html']
function scrollFunction() {
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50)
topBtn.style.display = 'block'
else topBtn.style.display = 'none'
}
window.onscroll = () => {
scrollFunction()
}
topBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth',
})
})
menuBtn.addEventListener('click', () => {
menu.classList.toggle('active')
menuBtn.classList.toggle('active')
})
projects.forEach((e, i) => {
e.addEventListener('click', () => {
window.open(urls[i], '_blank')
})
})