-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (80 loc) · 3.83 KB
/
script.js
File metadata and controls
95 lines (80 loc) · 3.83 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
85
86
87
88
89
90
91
92
93
94
95
document.addEventListener("DOMContentLoaded", function() {
const tabs = document.querySelectorAll(".code-container__tab");
const codeBlocks = document.querySelectorAll(".code-container__code");
tabs.forEach(tab => {
tab.addEventListener("click", function() {
const language = this.getAttribute("data-language");
// Remove active class from all tabs and code blocks
tabs.forEach(t => t.classList.remove("code-container__tab--active"));
codeBlocks.forEach(c => c.classList.remove("code-container__code--active"));
// Add active class to the clicked tab and corresponding code block
this.classList.add("code-container__tab--active");
document.querySelector(`.code-container__code--${language}`).classList.add("code-container__code--active");
// Re-highlight the code block for Prism.js
Prism.highlightElement(document.querySelector(`.code-container__code--${language} code`));
});
});
// FOOTER ANIMATION //
const footer = document.querySelector('.footer__inner');
const footerSpans = footer.querySelectorAll('span');
// intersectionobserver waits for viewer to get to certain point on page before triggering //
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
footerSpans.forEach((span, index) => {
setTimeout(() => {
span.classList.add('animate'); //this activates the span.activate part in CSS //
}, index * 100); //Delay each letter by 100ms
});
observer.unobserve(footer); //Unobserve after animation triggers
}
});
}, {
threshold: 0.1
});
observer.observe(footer);
});
document.addEventListener("DOMContentLoaded", function() {
const tabs = document.querySelectorAll(".code-container__tab");
const codeBlocks = document.querySelectorAll(".code-container__code");
tabs.forEach(tab => {
tab.addEventListener("click", function() {
const language = this.getAttribute("data-language");
// Remove active class from all tabs and code blocks
tabs.forEach(t => t.classList.remove("code-container__tab--active"));
codeBlocks.forEach(c => c.classList.remove("code-container__code--active"));
// Add active class to the clicked tab and corresponding code block
this.classList.add("code-container__tab--active");
document.querySelector(`.code-container__code--${language}`).classList.add("code-container__code--active");
// Re-highlight the code block for Prism.js
Prism.highlightElement(document.querySelector(`.code-container__code--${language} code`));
});
});
// Footer animation
const footer = document.querySelector('.footer__inner');
const footerSpans = footer.querySelectorAll('span');
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
footerSpans.forEach((span, index) => {
setTimeout(() => {
span.classList.add('animate');
}, index * 100); // Delay each letter by 100ms
});
observer.unobserve(footer); // Unobserve after animation triggers
}
});
}, {
threshold: 0.1
});
observer.observe(footer);
});
function copyCode() {
const codeElement = document.querySelector('.code-container__code--active code');
const codeText = codeElement.innerText;
navigator.clipboard.writeText(codeText).then(() => {
alert('Code copied to clipboard!');
}).catch(err => {
console.error('Failed to copy code: ', err);
});
}