Skip to content

Commit 716a425

Browse files
Hide particles when user prefers reduced motion (#16)
Just a thought based on #15. What if rather than fully remove the particles, we just hide the particles if the user prefers reduced motion. I don't have a personal preference regarding the floaty particles. But I know some people strongly dislike them, and I can see a very valid accessibility argument. This is just 'one way' to meet people in the middle, and provide a way to get rid of the particles. ### Description of Change a sprinkle of javascript added to the default page template. - Determine if user prefers reduced motion. - Toggle the particles based on preference. #### A Preview ![Screen Recording 2023-09-28 at 10 10 46 PM](https://github.com/rubycentral/rubycentral-theme/assets/71521423/44e72196-4411-42fe-8da4-e079e3ed9c1c)
1 parent 7c57eb9 commit 716a425

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

assets/particles/hideParticles.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const reducedMotionMediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
2+
3+
function displayParticlesBasedOnMotionPreferences() {
4+
if (reducedMotionMediaQuery.matches) {
5+
particles.style.display = "none";
6+
} else {
7+
particles.style.display = "block";
8+
}
9+
}
10+
11+
displayParticlesBasedOnMotionPreferences(); // run on page ready
12+
reducedMotionMediaQuery.addEventListener( // run on change
13+
'change', displayParticlesBasedOnMotionPreferences
14+
);

default.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</script>
6060
<div id="particles" style="position: fixed; top: 0; z-index: -10"></div>
6161
<script src="{{ asset "particles/hadron.d57b1908.js"}}"></script>
62+
<script src="{{ asset "particles/hideParticles.js" }}"></script>
6263
{{!-- Outputs important scripts - should always be included before closing body tag --}}
6364
{{ghost_foot}}
6465
</body>

0 commit comments

Comments
 (0)