-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
67 lines (55 loc) · 2.24 KB
/
main.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
function myMenuFunction() {
var navMenu = document.getElementById("myNavMenu");
if (navMenu.className.includes("responsive")) {
navMenu.className = "nav-menu";
} else {
navMenu.className += " responsive";
}
}
// Other JavaScript code
window.onscroll = function() {headerShadow()};
function headerShadow() {
const navHeader = document.getElementById("header");
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
navHeader.style.boxShadow = "0 1px 6px rgba(0, 0, 0, 0.1)";
navHeader.style.height = "70px";
navHeader.style.lineHeight = "70px";
} else {
navHeader.style.boxShadow = "none";
navHeader.style.height = "90px";
navHeader.style.lineHeight = "90px";
}
}
// Scroll active section
const sections = document.querySelectorAll('section[id]');
function scrollActive() {
const scrollY = window.scrollY;
sections.forEach(current => {
const sectionHeight = current.offsetHeight,
sectionTop = current.offsetTop - 50,
sectionId = current.getAttribute('id');
if(scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
document.querySelector('.nav-menu a[href*=' + sectionId + ']').classList.add('active-link');
} else {
document.querySelector('.nav-menu a[href*=' + sectionId + ']').classList.remove('active-link');
}
});
}
window.addEventListener('scroll', scrollActive);
document.querySelectorAll('.nav-menu .nav-link').forEach(link => {
link.addEventListener('click', () => {
document.getElementById("myNavMenu").classList.remove("responsive");
});
});
// document.getElementById('form-control').addEventListener('submit', function(event) {
// event.preventDefault();
// // These IDs from the previous steps
// const serviceID = 'service_1yl9u0b';
// const templateID = 'template_anypu6u';
// emailjs.sendForm(serviceID, templateID, '#form-control')
// .then(() => {
// alert('Message sent successfully!');
// }, (err) => {
// alert('Failed to send the message. Please try again later.', err);
// });
// });