-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
147 lines (111 loc) · 3.8 KB
/
script.js
File metadata and controls
147 lines (111 loc) · 3.8 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Target canvas element and ctx
const canvas = document.getElementById('bannerCanvas');
const ctx = canvas.getContext('2d');
// Create image object
const img = new Image();
img.src = 'Images/Banner.png';
//fade text
let alpha = 0;
//Outline animation variables
let outlineStartX = -400;
///calculate font size
function calcFontSize(canvasWidth) {
return Math.round(canvasWidth / 15);
}
// Function to draw on the canvas
function draw() {
// Calculate the aspect ratio
const aspectRatio = img.width / img.height;
// Set the canvas height based on the calculated aspect ratio
canvas.height = canvas.width / aspectRatio;
//clear canvas
ctx.clearRect(-10, -10, canvas.width +20, canvas.height +20);
// Draw the image
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
// Calculate and set heading font, size, and style
const fontSizeHeading = calcFontSize(canvas.width);
// console.log('Font Size Heading', fontSizeHeading);
ctx.font = `bold ${fontSizeHeading}px Pacifico`;
// fade in text effect
ctx.fillStyle = `rgba(0, 0, 0,${alpha})`;
if (alpha < 1) {
alpha += 0.005;
}
// Text coordinates
const headX = canvas.width * 0.05;
const headY = canvas.height * 0.5;
// Display heading text
ctx.fillText('About me', headX, headY);
//outline animation
const outlineFinalX = headX;
if (outlineStartX < outlineFinalX) {
outlineStartX += 2;
}
//adjust outline position
const outlineAdjust = 1;
// Display outline
ctx.strokeStyle = 'beige'; // Outline color
ctx.lineWidth = 2; // Outline thickness
ctx.strokeText('About me', outlineStartX -outlineAdjust, headY); ///Draw ouutline
// Set font, size, and style
const fontSizeText = fontSizeHeading / 2;
// console.log('Font Size Text', fontSizeText);
ctx.font = `bold ${fontSizeText}px Roboto`;
// Text coordinates
let textX = canvas.width * 0.05;
let textY = headY + fontSizeHeading;
// Gap between lines
const lineGap = fontSizeText * 1.5;
// Array containing the lines of text
const lines = [
"Kieran Sweetman",
"Noob Software Developer",
"Web3 Enthusiast",
"DeSci and Global Health Advocate"
];
// Loop for lines of text
for (let i = 0; i < lines.length; i++) {
ctx.fillStyle = `rgba(0, 0, 0, ${alpha})`;
ctx.fillText(lines[i], textX, textY);
ctx.strokeText(lines[i], outlineStartX, textY); ///Draw outline
ctx.strokeStyle = 'beige'; // Outline color
ctx.lineWidth = 2; // Outline thickness
textY += lineGap;
}
requestAnimationFrame(draw);
};
// Event listener for image load
img.onload = draw;
// Set up the canvas when the window has loaded
window.onload = function() {
// Set canvas width
canvas.width = window.innerWidth;
draw();
};
// Event listener for window resize
window.addEventListener('resize', function() {
// Update the canvas width
canvas.width = window.innerWidth;
///Reset outline start position
outlineStartX = -400;
// console.log('Canvas Width: ' + canvas.width);
draw();
});
//toggle burger menu when clicked
function toggleMenu() {
const navLinks = document.querySelector('.navbar ul');
navLinks.classList.toggle('show');
}
document.addEventListener('DOMContentLoaded', function () {
const fadeInElements = document.querySelectorAll('.fade-in');
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
});
fadeInElements.forEach(element => {
observer.observe(element);
});
});