-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (71 loc) · 2.5 KB
/
script.js
File metadata and controls
84 lines (71 loc) · 2.5 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
79
80
81
82
83
84
// Hamburger Menu (No need to manually control visibility since Bootstrap collapse handles this)
function hamburg() {
const navbar = document.querySelector(".navbar-collapse");
navbar.classList.add("show");
}
function cancel() {
const navbar = document.querySelector(".navbar-collapse");
navbar.classList.remove("show");
}
// Typewriter Effect
const texts = ["DEVELOPER", "DESIGNER", "YOUTUBER", "HACKER"];
let speed = 100;
const textElements = document.querySelector(".typewriter-text");
let textIndex = 0;
let charcterIndex = 0;
function typeWriter() {
if (charcterIndex < texts[textIndex].length) {
textElements.innerHTML += texts[textIndex].charAt(charcterIndex);
charcterIndex++;
setTimeout(typeWriter, speed);
} else {
setTimeout(eraseText, 1000);
}
}
function eraseText() {
if (textElements.innerHTML.length > 0) {
textElements.innerHTML = textElements.innerHTML.slice(0, -1);
setTimeout(eraseText, 50);
} else {
textIndex = (textIndex + 1) % texts.length;
charcterIndex = 0;
setTimeout(typeWriter, 500);
}
}
window.onload = typeWriter;
// Marquee Scrolling
document.addEventListener("DOMContentLoaded", () => {
const marquee = document.querySelector(".marquee-inner");
const speed = 1; // Scrolling speed
let scrollAmount = 0;
let isHovered = false;
// Duplicates the content for seamless scrolling
const marqueeContent = marquee.innerHTML;
marquee.innerHTML += marqueeContent;
const startScrolling = () => {
if (!isHovered) {
scrollAmount -= speed;
if (Math.abs(scrollAmount) >= marquee.scrollWidth / 2) {
scrollAmount = 0;
}
marquee.style.transform = `translateX(${scrollAmount}px)`;
}
requestAnimationFrame(startScrolling);
};
marquee.addEventListener("mouseover", () => {
isHovered = true; // Pause scrolling on hover
});
marquee.addEventListener("mouseout", () => {
isHovered = false; // Resume scrolling on mouse out
});
startScrolling(); // Start the scrolling effect
});
// Add interactivity for project cards
document.querySelectorAll(".project-card").forEach((card) => {
card.addEventListener("mouseover", () => {
card.style.transform = "scale(1.05)";
});
card.addEventListener("mouseout", () => {
card.style.transform = "scale(1)";
});
});