-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
159 lines (122 loc) · 3.61 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const app = {};
// Hamburger Menu
app.menuSlide = () => {
const menuLinks = $('.ham-link');
const checkbox = $('#ham-check');
menuLinks.on('click', function(){
checkbox.prop('checked', false);
})
}
// Arrow to Display About Me
app.arrowSlide = () => {
const arrow = $('.arrow');
arrow.on('click', function(){
$('html, body').animate({
scrollTop: $("#about").offset().top
}, 1500);
})
}
// Scroll back to top
app.backToTop = () => {
const upTop = $('#top');
upTop.on('click', function(){
$('html, body').animate({
scrollTop: $("#home").offset().top
}, 1500);
})
}
// Switch to Light Mode
app.switchLight = () => {
const toggleLight = $('#light-dark');
toggleLight.on('click', function(){
$('body').toggleClass('light');
})
}
// Doc Init
app.init = () => {
// Scrambling Letters Effect
const Messenger = function(el){
'use strict';
let m = this;
m.init = function(){
m.codeletters = "&#*+%?£@§$";
m.message = 0;
m.current_length = 0;
m.fadeBuffer = false;
m.messages = [
'Afua Deborah'
];
setTimeout(m.animateIn, 100);
};
m.generateRandomString = function(length){
let random_text = '';
while(random_text.length < length){
random_text += m.codeletters.charAt(Math.floor(Math.random()*m.codeletters.length));
}
return random_text;
};
m.animateIn = function(){
if(m.current_length < m.messages[m.message].length){
m.current_length = m.current_length + 2;
if(m.current_length > m.messages[m.message].length) {
m.current_length = m.messages[m.message].length;
}
let message = m.generateRandomString(m.current_length);
$(el).html(message);
setTimeout(m.animateIn, 20);
} else {
setTimeout(m.animateFadeBuffer, 20);
}
};
m.animateFadeBuffer = function(){
if(m.fadeBuffer === false){
m.fadeBuffer = [];
for(let i = 0; i < m.messages[m.message].length; i++){
m.fadeBuffer.push({c: (Math.floor(Math.random()*12))+1, l: m.messages[m.message].charAt(i)});
}
}
let do_cycles = false;
let message = '';
for(let i = 0; i < m.fadeBuffer.length; i++){
let fader = m.fadeBuffer[i];
if(fader.c > 0){
do_cycles = true;
fader.c--;
message += m.codeletters.charAt(Math.floor(Math.random()*m.codeletters.length));
} else {
message += fader.l;
}
}
$(el).html(message);
if(do_cycles === true){
setTimeout(m.animateFadeBuffer, 50);
} else {
setTimeout(m.cycleText, 2000);
}
};
m.cycleText = function(){
m.message = m.message + 1;
if(m.message >= m.messages.length){
m.message = 0;
}
m.current_length = 0;
m.fadeBuffer = false;
$(el).html('');
setTimeout(m.animateIn, 200);
};
m.init();
}
console.clear();
let messenger = new Messenger($('#messenger'));
app.menuSlide();
// Scroll To
app.arrowSlide();
app.backToTop();
// Light Mode
app.switchLight();
}
// Doc Ready
$(function(){
app.init();
AOS.init();
});