-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (58 loc) · 1.92 KB
/
Copy pathscript.js
File metadata and controls
73 lines (58 loc) · 1.92 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
const section1 = document.getElementById("section1");
const layer1 = document.getElementById("bg-layer1");
const layer2 = document.getElementById("bg-layer2");
const images = [
"/images/photo1.jpg",
"/images/photo2.jpg",
"/images/photo3.jpg",
"/images/photo4.jpg"
];
let currentIndex = 0;
let isLayer1Active = true;
layer1.style.backgroundImage = `url(${images[0]})`;
layer1.style.opacity = 1;
layer2.style.opacity = 0;
setInterval(() => {
currentIndex = (currentIndex + 1) % images.length;
if (isLayer1Active) {
layer2.style.backgroundImage = `url(${images[currentIndex]})`;
layer2.style.opacity = 1;
layer1.style.opacity = 0;
} else {
layer1.style.backgroundImage = `url(${images[currentIndex]})`;
layer1.style.opacity = 1;
layer2.style.opacity = 0;
}
isLayer1Active = !isLayer1Active;
}, 10000);
// Scroll reveal for about photo
const photoWrap = document.querySelector('.about-photo-wrap');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, { threshold: 0.2 });
if (photoWrap) observer.observe(photoWrap);
// Type Writer Cyber Section
const content = "Why Cyber Security?";
let typing = "";
const length = content.length;
const typewriter = document.getElementById("typewriter");
const cyberContent = document.getElementById("cyberPassion");
// Wrap in intersectionObserver to verify content is on the page
const observerTwo = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
for (let i = 0; i < content.length; i++) {
setTimeout(() => {
typewriter.textContent += content[i];
}, i * 120); // 0ms, 60ms, 120ms, 180ms...
}
cyberContent.classList.toggle('fade');
observerTwo.unobserve(entry.target);
}
});
}, {threshold: 1});
observerTwo.observe(typewriter);