-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
86 lines (73 loc) · 1.84 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
var text_color;
calcTextColor;
window.addEventListener('resize', calcTextColor);
function calcTextColor() {
if (window.matchMedia("(max-width: 600px)").matches) {
text_color = "white"
} else {
text_color = "black"
}
}
const carouselText = [
{ text: "Mitchell Billard", color: text_color },
{ text: "a Developer", color: text_color },
{ text: "a Pipeline TD", color: text_color },
];
$(document).ready(async function () {
carousel(carouselText, "#feature-text");
});
async function typeSentence(sentence, eleRef, delay = 100) {
const letters = sentence.split("");
let i = 0;
while (i < letters.length) {
await waitForMs(delay);
$(eleRef).append(letters[i]);
i++;
}
return;
}
async function deleteSentence(eleRef) {
const sentence = $(eleRef).html();
const letters = sentence.split("");
let i = 0;
while (letters.length > 0) {
await waitForMs(100);
letters.pop();
$(eleRef).html(letters.join(""));
}
}
async function carousel(carouselList, eleRef) {
var i = 0;
while (true) {
updateFontColor(eleRef, carouselList[i].color);
await typeSentence(carouselList[i].text, eleRef);
await waitForMs(1500);
await deleteSentence(eleRef);
await waitForMs(500);
i++;
if (i >= carouselList.length) {
i = 0;
}
}
}
function updateFontColor(eleRef, color) {
$(eleRef).css("color", color);
}
function waitForMs(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
$(document).ready(function() {
// Show or hide the sticky footer button
$(window).scroll(function() {
if ($(this).scrollTop() > 200) {
$('.go-to-top').fadeIn(200);
} else {
$('.go-to-top').fadeOut(200);
}
});
// Animate the scroll to top
$('.go-to-top').click(function(event) {
event.preventDefault();
$('html, body').animate({scrollTop: 0}, 300);
})
});