-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
131 lines (101 loc) · 5.06 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
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
123
124
125
126
127
128
129
130
/*===========================================Preloader=========================================*/
var loader = document.getElementById("preloader");
var delayInMilliseconds = 5; //1 second
window.addEventListener("load",function(){
setTimeout(function() {
loader.style.display = "none";
}, delayInMilliseconds);
})
/*============================================toggle icon navbar===============================*/
const themeButton = document.getElementById('theme')
const lightTheme = 'lightTheme'
const iconTheme = 'bx bx-moon'
// Previously selected topic (if user selected)
const selectedTheme = localStorage.getItem('selected-theme')
const selectedIcon = localStorage.getItem('selected-icon')
// We obtain the current theme that the interface has by validating the dark-theme class
const getCurrentTheme = () => document.body.classList.contains(lightTheme) ? 'dark' : 'light'
const getCurrentIcon = () => themeButton.classList.contains(iconTheme) ? 'bx bx-sun' : 'bx bx-moon'
// We validate if the user previously chose a topic
if (selectedTheme) {
// If the validation is fulfilled, we ask what the issue was to know if we activated or deactivated the dark
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](lightTheme)
themeButton.classList[selectedIcon === 'bx bx-moon' ? 'add' : 'remove'](iconTheme)
}
// Activate / deactivate the theme manually with the button
themeButton.addEventListener('click', () => {
// Add or remove the dark / icon theme
document.body.classList.toggle(lightTheme)
themeButton.classList.toggle(iconTheme)
// We save the theme and the current icon that the user chose
localStorage.setItem('selected-theme', getCurrentTheme())
localStorage.setItem('selected-icon', getCurrentIcon())
})
/*============================================toggle icon navbar===============================*/
let menuIcon = document.querySelector('#menu-icon');
let navbar = document.querySelector('.nav');
menuIcon.onclick = () => {
menuIcon.classList.toggle('bx-x');
navbar.classList.toggle('active');
};
/*=============================================nav active link================================*/
let sections = document.querySelectorAll('section');
let navlinks = document.querySelectorAll('header nav a');
window.onscroll = () => {
sections.forEach(sec => {
let top = window.scrollY;
let offset = sec.offsetTop - 150;
let height = sec.offsetHeight;
let id = sec.getAttribute('id');
if(top >= offset && top < offset + height) {
navlinks.forEach(links => {
links.classList.remove('active');
document.querySelector('header nav a[href*=' + id + ']').classList.add('active');
});
};
});
};
/*=================================sticky nav bar==========================================================*/
let header = document.querySelector('header');
header.classList.toggle('sticky',window.scrollY > 100);
/*=========================remove toggle icon and navbar when click navbar link=============================*/
menuIcon.classList.remove('bx-x');
menuIcon.classList.remove('active');
/*==================================scroll effect============================================================*/
ScrollReveal({
reset: true,
distance:'69px',
duration: 1500,
delay: 150
});
ScrollReveal().reveal('.home-content,.heading,.skills,.portfolio-container #pbtop, .container', { origin: 'top' });
ScrollReveal().reveal('.home-img,.box-container #box2,.portfolio-container #pbbuttom,.contact form,.skills .container .bar,.contact form #formBody', { origin: 'bottom' });
ScrollReveal().reveal('.home h1,.box-container #box1,.portfolio-container #pbleft,.about-img, .about-content h3,.education h4,.education .box-container .box .content h3,.education .box-container .boxleft,.contact form #input-boxleft ', { origin: 'left' });
ScrollReveal().reveal('.home p,.box-container #box3,.portfolio-container #pbright,.about-content p,.education .box-container .box .content p,.education .box-container .boxright,.contact form #input-boxright', { origin: 'right' });
/*===============================================typed js=================================================*/
const typed = new Typed('.multiple-text', {
strings:['Frontend Developer','Software Engineer','UI UX Developer','Graphic designer'],
typeSpeed:100,
backSpeed:100,
backDelay:1000,
loop:true
});
/*===============================================form =================================================*/
const form = document.querySelector("#form")
const submitButton = document.querySelector("#submitbtn")
const scriptURL = 'https://script.google.com/macros/s/AKfycbyryPCvtt1WpGIsC8E7ZboLfyHo317H-4eBS3lHFbZNaALgm9XFrrIU2uNEW2kTYd8Jiw/exec'
form.addEventListener('submit', e => {
submitButton.disabled = true
e.preventDefault()
let requestBody = new FormData(form)
fetch(scriptURL, { method: 'POST', body: requestBody})
.then(response => {
alert('Success!', response)
submitButton.disabled = false
})
.catch(error => {
alert('Error!', error.message)
submitButton.disabled = false
}
)
})