-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
45 lines (38 loc) · 1.52 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
window.addEventListener('DOMContentLoaded', function () {
window.addEventListener('scroll', function() {
const header = document.querySelector('header');
header.classList.toggle('sticky', window.scrollY > 0)
})
const menuBtn = document.querySelector('.menu-btn')
const navigation = document.querySelector('.navigation')
const navigationItems = document.querySelectorAll('.navigation a')
menuBtn.addEventListener('click', () => {
menuBtn.classList.toggle('active')
navigation.classList.toggle('active')
})
navigationItems.forEach(navItem => {
navItem.addEventListener('click', () => {
menuBtn.classList.remove('active')
navigation.classList.remove('active')
})
})
const scrollBtn = document.querySelector('.scrollToTop-btn')
window.addEventListener('scroll', () => {
scrollBtn.classList.toggle('active', window.scrollY > 500)
})
scrollBtn.addEventListener('click', () => {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
})
window.addEventListener('scroll', () => {
let reveals = document.querySelectorAll('.reveal')
for(let i = 0; i< reveals.length; i++) {
let windowHeight = window.innerHeight;
let revealTop = reveals[i].getBoundingClientRect().top;
let revealPoint = 50;
if(revealTop < windowHeight - revealPoint) {
reveals[i].classList.add('active')
}
}
})
})