Skip to content

Commit

Permalink
handle reduced motion
Browse files Browse the repository at this point in the history
  • Loading branch information
karsonkalt committed Oct 2, 2024
1 parent 7742860 commit 30145bd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
6 changes: 6 additions & 0 deletions _sass/custom-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,12 @@ article {
}
}

@media (prefers-reduced-motion: reduce) {
.wrapper:before {
animation: none;
}
}

@keyframes fadeInAndDown {
0% {
opacity: 0.5;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/home.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/index.js

Large diffs are not rendered by default.

42 changes: 24 additions & 18 deletions assets/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,27 @@ http://linkedin.com/in/kaltkarson

insertThemeButton();

document.addEventListener("scroll", () => {
const wrapper = document.querySelector(".wrapper") as HTMLElement;
const scrollTop = window.scrollY || document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = scrollTop / scrollHeight;

const vh = Math.max(
document.documentElement.clientHeight || 0,
window.innerHeight || 0
);

const vh50 = vh * 0.5;

const offset = scrollPercent * -vh50;

wrapper?.style.setProperty("--gradient-top-offset", `${offset}px`);
});
const prefersReducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;

if (!prefersReducedMotion) {
document.addEventListener("scroll", () => {
const wrapper = document.querySelector(".wrapper") as HTMLElement;
const scrollTop = window.scrollY || document.documentElement.scrollTop;
const scrollHeight =
document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = scrollTop / scrollHeight;

const vh = Math.max(
document.documentElement.clientHeight || 0,
window.innerHeight || 0
);

const vh50 = vh * 0.5;

const offset = scrollPercent * -vh50;

wrapper?.style.setProperty("--gradient-top-offset", `${offset}px`);
});
}

0 comments on commit 30145bd

Please sign in to comment.