-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (43 loc) · 1.01 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
// Typing text
const text = "Hi, I'm Kristin!";
const typingSpeed = 100;
const typingTextElement = document.getElementById('typing-text');
typingTextElement.classList.add('blinking-cursor');
function typeText() {
let i = 0;
const typingInterval = setInterval(function () {
if (i < text.length) {
typingTextElement.textContent += text.charAt(i);
i++;
} else {
clearInterval(typingInterval);
}
}, typingSpeed);
}
window.addEventListener('load', () => {
typeText();
});
// SCROLL TO TOP
const scrollBtn = document.getElementById('scrollBtn');
window.onscroll = function () {
if (
document.body.scrollTop > 700 ||
document.documentElement.scrollTop > 700
) {
scrollBtn.style.display = 'block';
} else {
scrollBtn.style.display = 'none';
}
};
scrollBtn.onclick = function () {
scrollToTop();
};
function scrollToTop() {
if (document.body.scrollTop != 0 || document.documentElement.scrollTop != 0) {
window.scrollTo({
top: 0,
behavior: 'smooth',
});
setTimeout(scrollToTop, 1000);
}
}