-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
78 lines (60 loc) · 2.39 KB
/
Copy pathindex.js
File metadata and controls
78 lines (60 loc) · 2.39 KB
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
window.onload = setUpFunctionality;
function setUpFunctionality() {
setUpInterestsHoverFunctionality();
setUpTimeline();
}
function setUpInterestsHoverFunctionality() {
let homeInterestsList = document.getElementById('homeInterestsList');
let homeInterestsSection = document.getElementById('homeInterestsSection');
// Iterate through the interests lists and obtain each li element
homeInterestsList.childNodes.forEach((listElement) => {
// each list element has a data attribute called index that aligns the list element to the right homeInterestsInfo
if (listElement.dataset != undefined) {
let listIndex = listElement.dataset.index;
let correspondingElement = findElementWithCorrespondingDataIndex(listIndex, homeInterestsSection);
// Set on hover listener
listElement.addEventListener("mouseover", () => {
correspondingElement.style.opacity = "1";
correspondingElement.style.transform = "scale(1.15, 1.15)";
// correspondingElement.style.display = "block";
})
// Set on hover exit listener
listElement.addEventListener("mouseout", () => {
correspondingElement.style.opacity = "0";
correspondingElement.style.transform = "scale(1, 1)";
// correspondingElement.style.display = "none";
})
}
})
}
// HELPER FUNCTIONS
function findElementWithCorrespondingDataIndex(dataIndex, elementGroupToSearch) {
var node = null;
elementGroupToSearch.childNodes.forEach((childNode) => {
if (childNode.dataset != null) {
if (childNode.dataset.index === dataIndex) {
node = childNode;
}
}
});
return node;
}
// Timeline functionality
function setUpTimeline() {
// Add scroll reveal animation for timeline items
const timelineItems = document.querySelectorAll('.timeline-item');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateX(0)';
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
timelineItems.forEach(item => {
observer.observe(item);
});
}