-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (96 loc) · 3.32 KB
/
Copy pathscript.js
File metadata and controls
122 lines (96 loc) · 3.32 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
const body = document.body
const btnTheme = document.querySelector('.fa-moon')
const btnHamburger = document.querySelector('.fa-bars')
const addThemeClass = (bodyClass, btnClass) => {
body.classList.add(bodyClass)
btnTheme.classList.add(btnClass)
}
const getBodyTheme = localStorage.getItem('portfolio-theme')
const getBtnTheme = localStorage.getItem('portfolio-btn-theme')
addThemeClass(getBodyTheme, getBtnTheme)
const isDark = () => body.classList.contains('dark')
const setTheme = (bodyClass, btnClass) => {
body.classList.remove(localStorage.getItem('portfolio-theme'))
btnTheme.classList.remove(localStorage.getItem('portfolio-btn-theme'))
addThemeClass(bodyClass, btnClass)
localStorage.setItem('portfolio-theme', bodyClass)
localStorage.setItem('portfolio-btn-theme', btnClass)
}
const toggleTheme = () =>
isDark() ? setTheme('light', 'fa-moon') : setTheme('dark', 'fa-sun')
btnTheme.addEventListener('click', toggleTheme)
const displayList = () => {
const navUl = document.querySelector('.nav__list')
if (btnHamburger.classList.contains('fa-bars')) {
btnHamburger.classList.remove('fa-bars')
btnHamburger.classList.add('fa-times')
navUl.classList.add('display-nav-list')
} else {
btnHamburger.classList.remove('fa-times')
btnHamburger.classList.add('fa-bars')
navUl.classList.remove('display-nav-list')
}
}
btnHamburger.addEventListener('click', displayList)
const scrollUp = () => {
const btnScrollTop = document.querySelector('.scroll-top')
if (
body.scrollTop > 500 ||
document.documentElement.scrollTop > 500
) {
btnScrollTop.style.display = 'block'
} else {
btnScrollTop.style.display = 'none'
}
}
document.addEventListener('scroll', scrollUp)
emailjs.init('1qFZO2oYoxLzYAsQL'); //email js user id/public key
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
// Fetch form values
let form = this;
console.log(form)
let formData = {
from_name: form.email.value,
to_name: 'Athul Tom Mathew', // Replace with recipient's name
subject: `new message from ${form.name.value}`,
message: form.message.value
};
// Send email
emailjs.send(/*your_service_id*/'service_athultm16' ,/*your_template_id*/ 'template_athultm16', formData)
.then(function(response) {
console.log('Email sent!', response);
alert('Email sent successfully!');
form.reset();
}, function(error) {
console.error('Error sending email:', error);
alert('Error sending email! Please try again later.');
});
});
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('.section');
const options = {
root: null,
rootMargin: '0px',
threshold: 0.1 // Trigger animation when 10% of the section is visible
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const section = entry.target;
// Apply animation based on section index
const index = Array.from(sections).indexOf(section);
if (index % 2 === 0) {
section.classList.add('section--animate-right');
} else {
section.classList.add('section--animate-left');
}
// Stop observing the section after it becomes visible
observer.unobserve(section);
}
});
}, options);
sections.forEach(section => {
observer.observe(section);
});
});