Skip to content

Commit a9dea39

Browse files
committed
some improvements
1 parent dbcc8d6 commit a9dea39

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

_layouts/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta http-equiv="X-UA-Compatible" content="IE=edge">
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010
<link rel="preload" as="font" href="/assets/fonts/iosevka-regular.woff2" type="font/woff2" crossorigin="anonymous">
11-
<link rel="preload" as="script" href="/assets/scripts/palette.js" >
11+
<link rel="preload" as="script" href="/assets/scripts/palette.js">
1212
<link rel="stylesheet" href="/assets/styles/styles.css">
1313
</head>
1414
<body>

assets/scripts/effects.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Initial ascii stuff (Look, I don't like creating a temporary canvas either, but...)
44

55
const context = document.createElement('canvas').getContext('2d')
6-
context.font = getComputedStyle(document.querySelector(".ascii")).font
6+
context.font = getComputedStyle(document.querySelector('.ascii')).font
77
const charDimensions = context.measureText('.') // Monospace font assumed
88
const charWidth = charDimensions.width
99
const charHeight = charDimensions.fontBoundingBoxAscent
@@ -17,6 +17,29 @@ const seaTPS = 3;
1717
const seaText = []
1818
const seaChars = ['~']
1919

20+
function setOptimizedInterval(element, render, tps) {
21+
render()
22+
let handle = setInterval(render, 1000 / tps)
23+
new IntersectionObserver((entries) => {
24+
entries.forEach((entry) => {
25+
if(entry.intersectionRatio >= 0.05) {
26+
if(handle === null) {
27+
console.log('Show animation on', element)
28+
handle = setInterval(render, 1000 / tps)
29+
}
30+
} else if(handle != null) {
31+
console.log('Hide animation on', element)
32+
clearInterval(handle)
33+
handle = null
34+
}
35+
})
36+
}, {
37+
root: null,
38+
rootMargin: '0px',
39+
threshold: [0.05, 0.06],
40+
}).observe(element)
41+
}
42+
2043
function randomSeaChar() {
2144
return seaChars[Math.floor(Math.random() * seaChars.length)]
2245
}
@@ -33,5 +56,4 @@ function updateSea() {
3356
seaElement.innerText = seaText.join('')
3457
}
3558

36-
updateSea();
37-
window.setInterval(updateSea, 1000 / seaTPS)
59+
setOptimizedInterval(seaElement, updateSea, seaTPS)

assets/scripts/palette.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,12 @@ function rotateUserPalette() {
1414
: 'light'
1515
}
1616

17-
function getAppliedPalette(palette) {
18-
if (palette === 'light') {
19-
return 'light'
20-
}
21-
22-
if (palette === 'dark') {
23-
return 'dark'
24-
}
25-
}
26-
2717
function setAppliedPalette(palette) {
2818
document.documentElement.dataset.palette = palette
2919
}
3020

3121
const userPalette = getUserPalette()
32-
setAppliedPalette(getAppliedPalette(userPalette))
22+
setAppliedPalette(userPalette)
3323
document.querySelector("#toggle-palette").addEventListener("click", () => {
3424
const newPalette = rotateUserPalette(getUserPalette())
3525
setAppliedPalette(newPalette)

assets/styles/styles.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
---
2-
---
3-
41
@font-face {
52
font-family: Iosevka;
63
font-display: swap;
@@ -73,6 +70,7 @@ a {
7370
position: absolute;
7471
bottom: 0vh;
7572
left: 0;
73+
/* animation: water 1s ease-in-out 0s infinite alternate; */
7674
}
7775

7876
.navbar {

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
<h1 id="name">Henry Langmack</h1>
1616
<p class="ascii sea"></div>
1717
</header>
18+
<!--
19+
{% for num in (1..100) %}
20+
<br>
21+
{% endfor %} -->
1822

1923
<button id="toggle-palette"></button>

0 commit comments

Comments
 (0)