Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect reduced motion preferences #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions html/jizz/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@
}
}

const preload=document.createElement("link");
preload.rel="preload";
//not supported by some Chromium based browsers https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload#browser_compatibility
//Firefox also warns "Preload of ... was ignored due to unknown “as” or “type” values, or non-matching “media” attribute."
preload.as="document";

document.addEventListener("click",function(event){
let anchor = event.target
while(anchor){
if(anchor.tagName=='A' && anchor.href){
event.preventDefault();
//preload next website while animation plays out
//(not working, but what the hell. I did it like in the MDN example. Not my fault.)
let preload=document.createElement("link");
preload.href=anchor.href;
preload.rel="preload";
preload.as="document";
document.head.appendChild(preload);
//reversing load-in animation
let overlay = document.getElementById("overlay");
overlay.getAnimations()[0].reverse();
//wait 500ms for animation to finish and then redirect
setTimeout(()=>{window.location.href=anchor.href},500);
return;
}
anchor=anchor.parentElement;//checking if parent contains a link
}
},false);
let anchor = event.target
while(anchor) {
if (anchor.tagName == 'A' && anchor.href) {
const href=anchor.href;
event.preventDefault();
//preload next website while animation plays out
preload.href=href;
document.head.appendChild(preload);
//reversing load-in animation
const animation = document.getElementById("overlay").getAnimations()[0];
// wait for the animation to finish and then redirect
animation.addEventListener('finish', () => window.location.href = href);
animation.reverse();
}
anchor = anchor.parentElement;
}
});

window.addEventListener("focus",function(event){
let overlay = document.getElementById("overlay");
Expand Down
3 changes: 3 additions & 0 deletions html/style/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
font-size:var(--content-width);
}
}
@media (prefers-reduced-motion) {
@keyframes load-in {}
}
/* body */
body{
/* color legend:
Expand Down