-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
83 lines (65 loc) · 2.35 KB
/
scripts.js
File metadata and controls
83 lines (65 loc) · 2.35 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
const btn = document.getElementById('submit-btn-val');
document.getElementById('form')
.addEventListener('submit', function (event) {
event.preventDefault();
btn.innerText = 'Sending...';
const serviceID = 'default_service';
const templateID = 'template_2052l8x';
emailjs.sendForm(serviceID, templateID, this)
.then(() => {
btn.innerText = 'Send a Message';
alert('Email Sent!');
}, (err) => {
btn.innerText = 'Send a Message';
alert(JSON.stringify(err));
});
});
var typed = new Typed('#element', {
strings: ['Puzzle Solver', 'Leetcoder', 'Graphic Designer', 'Web Developer'],
typeSpeed: 50,
});
const sections = document.querySelectorAll('.section');
const secBtns = document.querySelectorAll('.controls');
const secBtn = document.querySelectorAll('.control');
const allSection = document.querySelector('.main-content');
function DynamicWork() {
//For toggle the nav buttons
for (let i = 0; i < secBtn.length; i++) {
secBtn[i].addEventListener('click', function () {
let tmp = document.querySelectorAll('.active-btn');
tmp[0].className = tmp[0].className.replace('active-btn', '');
this.className += ' active-btn' //what is the logic of this.classname inside a function.
})
}
//For rendering the sections on clicking nav buttons
allSection.addEventListener('click', (e) => {
const id = e.target.dataset.id;
// fetch the section with selected id
for (let i = 0; i < sections.length; i++) {
if (sections[i].id == id) {
let tmp = document.querySelectorAll('.active');
tmp[0].className = tmp[0].className.replace('active', '');
sections[i].className += ' active'
}
}
// Another approach
// if(id){
// secBtns.forEach((btn) =>{
// btn.classList.remove('active')
// })
// e.target.classList.add('active');
// sections.forEach((section)=>{
// section.classList.remove('active')
// })
// const element = document.getElementById(id);
// element.classList.add('active');
// }
})
/*light-mode toggle*/
const themeBtn = document.querySelector('.theme-btn');
themeBtn.addEventListener('click', () => {
let ele = document.body;
ele.classList.toggle('light-mode');
})
}
DynamicWork()