-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
103 lines (84 loc) · 2.83 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
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
document.addEventListener("DOMContentLoaded", function () {
const aboutLink = document.querySelector('a[href="#about"]');
const projectsLink = document.querySelector('a[href="#projects"]');
const skillsLink = document.querySelector('a[href="#skills"]');
const contactLink = document.querySelector('a[href="#contact"]');
const scrollToSection = function (event, sectionId) {
event.preventDefault();
const section = document.getElementById(sectionId);
const sectionOffsetTop = section.offsetTop;
const windowHeight = window.innerHeight;
const scrollToPosition = sectionOffsetTop - windowHeight / 16;
window.scrollTo({
top: scrollToPosition,
behavior: "smooth",
});
};
aboutLink.addEventListener("click", function (event) {
scrollToSection(event, "about");
});
projectsLink.addEventListener("click", function (event) {
scrollToSection(event, "projects");
});
skillsLink.addEventListener("click", function (event) {
scrollToSection(event, "skills");
});
contactLink.addEventListener("click", function (event) {
scrollToSection(event, "contact");
});
});
function hideImageContainer() {
const elements = document.getElementsByClassName("portfolio-image-container");
// Retrieve all elements with the class name 'portfolio-image-container'
for (let i = 0; i < elements.length; i++) {
// Loop through each element
elements[i].style.display = window.innerWidth <= 768 ? "none" : "";
// Set the display property to 'none' if the window width is 768 pixels or less
// Otherwise, set it to an empty string to restore the default display
}
}
window.addEventListener("load", hideImageContainer);
// Call the hideImageContainer function when the page finishes loading
window.addEventListener("resize", hideImageContainer);
// Call the hideImageContainer function when the window is resized
function typeWriter() {
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const j = element.innerHTML.length; // Separate j variable for each element
if (j < jTxt.length) {
element.innerHTML += jTxt.charAt(j);
}
}
let complete = true;
for (let i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.length < jTxt.length) {
complete = false;
break;
}
}
if (!complete) {
setTimeout(typeWriter, jSpeed);
}
}
document.addEventListener("DOMContentLoaded", function () {
typeWriter();
});
function scrollToTop() {
let up = document.getElementById("up-button-container");
let content = document.getElementById("content");
up.style.display = "none";
window.addEventListener("scroll", function () {
if (window.scrollY > content.offsetTop) {
up.style.display = "block";
} else {
up.style.display = "none";
}
});
up.addEventListener("click", function () {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
}
window.addEventListener("DOMContentLoaded", scrollToTop());