mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-14 03:23:41 +02:00
wip(22w7b): add visibilitychange event
This commit is contained in:
parent
bb0d98c560
commit
75b7282411
4 changed files with 78 additions and 22 deletions
|
@ -38,7 +38,9 @@ body {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
:is(#intro, #card) a {
|
||||||
|
--padding-vert: 17px;
|
||||||
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -76,7 +78,7 @@ body > div {
|
||||||
}
|
}
|
||||||
|
|
||||||
#intro a {
|
#intro a {
|
||||||
padding: 17px 40px;
|
padding: var(--padding-vert) 40px;
|
||||||
border-radius: 100px;
|
border-radius: 100px;
|
||||||
border: solid 4px rgba(var(--color-contrast), .3);
|
border: solid 4px rgba(var(--color-contrast), .3);
|
||||||
margin: var(--padding) 0;
|
margin: var(--padding) 0;
|
||||||
|
@ -98,7 +100,7 @@ body > div {
|
||||||
}
|
}
|
||||||
|
|
||||||
#card {
|
#card {
|
||||||
--portrait-size: calc(128px, 15vw, 11vh);
|
--portrait-size: 128px;
|
||||||
|
|
||||||
gap: var(--padding);
|
gap: var(--padding);
|
||||||
position: relative;
|
position: relative;
|
||||||
|
@ -121,30 +123,43 @@ body > div {
|
||||||
|
|
||||||
#card a {
|
#card a {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 17px 0;
|
padding: var(--padding-vert) 0;
|
||||||
border-radius: 9px;
|
border-radius: 9px;
|
||||||
background-color: rgba(var(--color-contrast), .13);
|
background-color: rgba(var(--color-contrast), .13);
|
||||||
box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .24);
|
box-shadow:
|
||||||
|
inset 0 3px 16px rgba(0, 0, 0, 0),
|
||||||
|
0 1px 3px rgba(0, 0, 0, .12),
|
||||||
|
0 1px 2px rgba(0, 0, 0, .24);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- Media Queries -- */
|
/* -- Media Queries -- */
|
||||||
|
|
||||||
|
@supports (not (backdrop-filter: saturate)) and (not (backdrop-filter: brightness)) {
|
||||||
|
#card {
|
||||||
|
background-color: rgba(var(--color-base), .2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (pointer: fine) {
|
@media (pointer: fine) {
|
||||||
#intro a:hover {
|
:is(#intro, #card) a {
|
||||||
background-color: rgba(var(--color-contrast), .1);
|
--transition-speed: 200ms;
|
||||||
|
transition: var(--transition-speed) background-color, var(--transition-speed) box-shadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
#card a:hover {
|
:is(#intro, #card) a:hover {
|
||||||
background-color: rgba(var(--color-contrast), .2);
|
background-color: rgba(var(--color-contrast), .2);
|
||||||
box-shadow: 0 3px 6px rgba(0, 0, 0,.16), 0 3px 6px rgba(0, 0, 0, .23);
|
box-shadow:
|
||||||
|
inset 0 3px 16px rgba(0, 0, 0, .16),
|
||||||
|
0 3px 6px rgba(0, 0, 0, .16),
|
||||||
|
0 3px 6px rgba(0, 0, 0, .23);
|
||||||
|
}
|
||||||
|
|
||||||
|
:is(#intro, #card) a:active {
|
||||||
|
background-color: rgba(var(--color-contrast), .15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-aspect-ratio: 14/9) and (min-height: 450px) {
|
@media (min-aspect-ratio: 14/9) and (min-height: 450px) {
|
||||||
#intro a {
|
|
||||||
width: unset;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
@ -154,4 +169,16 @@ body > div {
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body > div:last-of-type {
|
||||||
|
padding: calc(var(--padding) * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#intro a {
|
||||||
|
width: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
#card {
|
||||||
|
min-width: 300px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,22 @@ export default class Background {
|
||||||
count: 2
|
count: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
this.image = null;
|
this.image = null; // Will contain the original base64 image
|
||||||
this.target = target ? target : document.body;
|
this.target = target ? target : document.body; // Set `background-image` of this element
|
||||||
|
|
||||||
this.updateBg = setInterval(() => this.randBg(), 5000);
|
// Update the background with a new image every now and then
|
||||||
|
this.updateBg = {
|
||||||
|
_this: this,
|
||||||
|
_delay: 5000,
|
||||||
|
_interval: null,
|
||||||
|
set running (state = true) {
|
||||||
|
clearInterval(this._interval);
|
||||||
|
if(state) this._interval = setInterval(() => this._this.randBg(), this._delay);
|
||||||
|
},
|
||||||
|
set delay (delay) {
|
||||||
|
this._delay = delay;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the target CSS background
|
// Update the target CSS background
|
||||||
|
|
|
@ -10,12 +10,17 @@ export default class Glitch extends Background {
|
||||||
// Queue the next glitch
|
// Queue the next glitch
|
||||||
set next (timeout) {
|
set next (timeout) {
|
||||||
clearTimeout(this._interval);
|
clearTimeout(this._interval);
|
||||||
this._interval = setTimeout(() => this._this.glitch(), timeout);
|
if(timeout !== false) this._interval = setTimeout(() => this._this.glitch(), timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.interval.next = 500;
|
// Stop playback when page is not visible
|
||||||
this.randBg();
|
document.addEventListener("visibilitychange",() => {
|
||||||
|
if(document.visibilityState === "visible") return this.start();
|
||||||
|
this.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate random string of length from charset
|
// Generate random string of length from charset
|
||||||
|
@ -28,10 +33,23 @@ export default class Glitch extends Background {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a glitchy image
|
// Create a glitchy image and queue the next one
|
||||||
glitch() {
|
glitch() {
|
||||||
|
if(!this.image) return;
|
||||||
const image = this.image.replaceAll(this.randStr(), this.randStr());
|
const image = this.image.replaceAll(this.randStr(), this.randStr());
|
||||||
this.setBg(image);
|
this.setBg(image);
|
||||||
|
|
||||||
this.interval.next = this.randInt(1500, 5000);
|
this.interval.next = this.randInt(1500, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
this.interval.next = 500;
|
||||||
|
this.updateBg.running = true;
|
||||||
|
this.randBg();
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
this.interval.next = false;
|
||||||
|
this.updateBg.running = false;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,8 +31,7 @@
|
||||||
<p>Beyond computer science, I'm also a armchair rabbit-holer for engineering, astronomy and physics</p>
|
<p>Beyond computer science, I'm also a armchair rabbit-holer for engineering, astronomy and physics</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h1>☕</h1>
|
<p>...and ☕, full-time</p>
|
||||||
<p>...and coffee, full-time</p>
|
|
||||||
</div>
|
</div>
|
||||||
<a href="#">stalk me 😬</a>
|
<a href="#">stalk me 😬</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue