-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
140 lines (102 loc) · 3.57 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
131
132
133
134
135
136
137
138
139
140
// smooth scroll
var scroll = new SmoothScroll('[data-scroll]', {
speed: 500,
speedAsDuration: true
});
// typing animation
const texts = ["Hi, I'm Bai.", "Junior Developer. I aspire to deliver smart solutions that serve the community."];
const h1 = document.querySelector('.h1-typing');
const h2 = document.querySelector('.h2-typing');
const button1 = document.querySelector('.view-projects');
const button2 = document.querySelector('.view-resume');
let count = 0; // 0 - h1, 1 - h2
let index = 0; // index of letters
let currentText = "";
let letter = "";
(function h1type(){
currentText = texts[count]; // start with 0 aka h1 first
letter = currentText.slice(0, ++index);
h1.textContent = letter;
if (letter.length == currentText.length) {
h1.classList.add('hide-border');
h2.style.display = 'block';
index = 0;
return setTimeout(h2type, 200);
}
setTimeout(h1type, 100);
})(); // this function is called when page is loaded
function h2type(){
currentText = texts[1];
letter = currentText.slice(0, ++index);
h2.textContent = letter;
if(letter.length == currentText.length) {
return callToAction();
}
setTimeout(h2type, 50);
}
function callToAction(){
button1.style.opacity = '1';
button2.style.opacity = '2';
}
// terminal transition
const aboutTab = document.getElementById('about-tab');
const projectsTab = document.getElementById('projects-tab');
const aboutSection = document.querySelector('.terminal-about')
const projectSection = document.querySelector('.terminal-project-gallery');
aboutTab.addEventListener('click', function(e) {
if (!aboutTab.classList.contains('current-tab')){
aboutTab.classList.add('current-tab');
projectsTab.classList.remove('current-tab');
projectSection.classList.add('hide');
aboutSection.classList.remove('hide');
}
});
projectsTab.addEventListener('click', function(e) {
if (!projectsTab.classList.contains('current-tab')) {
projectsTab.classList.add('current-tab');
aboutTab.classList.remove('current-tab');
aboutSection.classList.add('hide');
projectSection.classList.remove('hide');
}
});
// modal
const projectImg = document.querySelectorAll('.img-wrapper');
const modal = document.querySelector('.modal');
const body = document.querySelector('body');
projectImg.forEach(image => {
image.addEventListener('click', function(e) {
// get parent class: project item
let projectItem = image.parentElement;
//console.log(projectItem);
// get id of project item, get number at the back
let projectIndex = 'project-modal-'.concat(projectItem.id.split('-')[2]);
//console.log(projectIndex);
// get modal by id project-modal-(number)
let projectModal = document.getElementById(projectIndex);
//console.log(projectModal.classList);
modal.style.display = 'block';
body.classList.add('modal-open');
projectModal.classList.remove('hide');
})});
// hide modals
const allModals = document.querySelectorAll('.modal-content');
function hideAllModals(){
allModals.forEach(modal => {
if(!(modal.classList.contains('hide'))){
modal.classList.add('hide')}});
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
body.classList.remove('modal-open');
hideAllModals();
}
};
// When the user clicks on red button, close it
const closeButton = document.querySelector('.close-button');
closeButton.addEventListener('click', function(e) {
closeButton.parentElement.parentElement.parentElement.style.display = "none";
body.classList.remove('modal-open');
hideAllModals();
});