-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
66 lines (50 loc) · 2.03 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
// Function to open a specific tab content
function openTab(evt, tabName) {
let i, tabcontent, tablinks;
// Hide all tab content
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Deactivate all tab buttons
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the selected tab content and mark the button as active
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
function getRandomPercentage() {
// Generate random percentage between -25 and 25
return (Math.random() * 50 - 25).toFixed(2);
}
function updatePercentageBasedOnDirection(isUp) {
const percentageElement = document.querySelector('.percentage');
// Generate a percentage value based on the arrow's direction
let newValue;
if (isUp) {
newValue = (Math.random() * 25).toFixed(2); // Positive values (0 to 25%)
} else {
newValue = (Math.random() * -25).toFixed(2); // Negative values (-25% to 0)
}
// Update the percentage text
percentageElement.textContent = `${newValue}%`;
// Change color based on value (green for positive, red for negative)
percentageElement.style.color = isUp ? 'green' : 'red';
}
// This function syncs the arrow movement (up or down) with the percentage update
function syncWithArrow() {
let isUp = false; // Start with the arrow pointing up
// Set interval to update based on the CSS keyframe timing (5 seconds)
setInterval(() => {
updatePercentageBasedOnDirection(isUp);
// Toggle the arrow's direction
isUp = !isUp;
}, 2500); // 2500ms for half of the animation cycle (to match arrow direction change)
}
// Start syncing when the page loads
syncWithArrow();
// By default, open the Home tab
document.getElementById("Home").style.display = "block";
document.querySelector('.tablinks').className += " active";