-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
98 lines (88 loc) · 2.76 KB
/
app.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
//Experience section animation
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
document.getElementById("defaultOpen").click();
//Navigation bar scroll animation
var prevScrollpos = window.pageYOffset;
window.onscroll = function () {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.querySelector(".navbar").style.top = "0";
} else {
document.querySelector(".navbar").style.top = "-1000px";
}
prevScrollpos = currentScrollPos;
};
//Smooth scroll animation
function smoothscroll(target, duration) {
var target = document.querySelector(target);
var targetpos = target.getBoundingClientRect().top;
var startpos = window.pageYOffset;
var dist = targetpos - startpos;
var starttime = null;
function anime(currentTime) {
if (starttime === null) starttime = currentTime;
var timeelapsed = currentTime - starttime;
var run = ease(timeelapsed, startpos, dist, duration);
window.scrollTo(0, run);
if (timeelapsed < duration) requestAnimationFrame(anime);
}
function ease(t, b, c, d) {
t /= d / 2;
if (t < 1) return (c / 2) * t * t + b;
t--;
return (-c / 2) * (t * (t - 2) - 1) + b;
}
requestAnimationFrame(anime);
}
var section1 = document.querySelector(".ed");
var section2 = document.querySelector(".ex");
var section3 = document.querySelector(".pro");
var section4 = document.querySelector(".con");
section1.addEventListener("click", function () {
smoothscroll("#education", 1000);
});
section2.addEventListener("click", function () {
smoothscroll("#experience", 1000);
});
section3.addEventListener("click", function () {
smoothscroll("#project", 1000);
});
section4.addEventListener("click", function () {
smoothscroll("#contact", 1000);
});
//Typewriting animation
const texts = ["Aman Budhraja"];
let count = 0;
let index = 0;
let currenttext = "";
let letter = "";
(function type() {
if (count === texts.length) {
count = 0;
}
currenttext = texts[count];
letter = currenttext.slice(0, ++index);
document.querySelector(".typing").textContent = letter;
if (letter.length === currenttext.length) {
count++;
index = 0;
}
setTimeout(type, 300);
})();
//Preloading animation
window.addEventListener("load", function () {
const preloader = document.querySelector(".preload");
preloader.classList.add("finish");
});