-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
63 lines (49 loc) · 1.7 KB
/
main.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
const dynamicContent = document.getElementById("dynamictext");
const phrases = ["Community Enthusiast...", "Student at SSTC...", "Open-Source Contributor...", "Human Being..."]
let pharseIndex = 0;
let letterIndex = 0;
const typingSpeed = 150;
const erasingSpeed = 100;
function printLetters(phrase) {
if (letterIndex == phrase.length) {
// clear letter which have been typed
clearLetters();
}
else if (letterIndex < phrase.length) {
dynamicContent.textContent += phrase.charAt(letterIndex);
letterIndex += 1;
setTimeout(function () {
printLetters(phrase)
}, typingSpeed)
}
}
function clearLetters() {
if (letterIndex == -1) {
pharseIndex = (pharseIndex + 1) % phrases.length;
letterIndex = 0;
printLetters(phrases[pharseIndex])
}
else if (letterIndex > -1) {
let updatedPhrase = "";
for (let index = 0; index < letterIndex; index++) {
updatedPhrase += phrases[pharseIndex].charAt(index);
}
dynamicContent.textContent = updatedPhrase;
letterIndex -= 1;
setTimeout(clearLetters, erasingSpeed)
}
}
printLetters(phrases[pharseIndex])
let mybutton = document.getElementById("myBtn");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}