-
Notifications
You must be signed in to change notification settings - Fork 10
/
script.js
114 lines (93 loc) · 2.94 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
$(document).ready(function() {
//sticky header
$(window).scroll(function() {
if ($(this).scrollTop() > 1) {
$(".header-area").addClass("sticky");
} else {
$(".header-area").removeClass("sticky");
}
// Update the active section in the header
updateActiveSection();
});
$(".header ul li a").click(function(e) {
e.preventDefault();
var target = $(this).attr("href");
if ($(target).hasClass("active-section")) {
return;
}
if (target === "#home") {
$("html, body").animate(
{
scrollTop: 0
},
500
);
} else {
var offset = $(target).offset().top - 40;
$("html, body").animate(
{
scrollTop: offset
},
500
);
}
$(".header ul li a").removeClass("active");
$(this).addClass("active");
});
//Initial content revealing js
ScrollReveal({
distance: "100px",
duration: 2000,
delay: 200
});
ScrollReveal().reveal(".header a, .profile-photo, .about-content, .education", {
origin: "left"
});
ScrollReveal().reveal(".header ul, .profile-text, .about-skills, .internship", {
origin: "right"
});
ScrollReveal().reveal(".project-title, .contact-title", {
origin: "top"
});
ScrollReveal().reveal(".projects, .contact", {
origin: "bottom"
});
//contact form to excel sheet
const scriptURL = 'https://script.google.com/macros/s/AKfycbzUSaaX3XmlE5m9YLOHOBrRuCh2Ohv49N9bs4bew7xPd1qlgpvXtnudDs5Xhp3jF-Fx/exec';
const form = document.forms['submitToGoogleSheet']
const msg = document.getElementById("msg")
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form) })
.then(response => {
msg.innerHTML = "Message sent successfully"
setTimeout(function () {
msg.innerHTML = ""
}, 5000)
form.reset()
})
.catch(error => console.error('Error!', error.message))
})
});
function updateActiveSection() {
var scrollPosition = $(window).scrollTop();
// Checking if scroll position is at the top of the page
if (scrollPosition === 0) {
$(".header ul li a").removeClass("active");
$(".header ul li a[href='#home']").addClass("active");
return;
}
// Iterate through each section and update the active class in the header
$("section").each(function() {
var target = $(this).attr("id");
var offset = $(this).offset().top;
var height = $(this).outerHeight();
if (
scrollPosition >= offset - 40 &&
scrollPosition < offset + height - 40
) {
$(".header ul li a").removeClass("active");
$(".header ul li a[href='#" + target + "']").addClass("active");
}
});
}