Skip to content

Commit

Permalink
Add support for reduced-motion to new bing-bong feature and to the lo…
Browse files Browse the repository at this point in the history
…ader
  • Loading branch information
fymmot committed Jan 27, 2024
1 parent a9bca3b commit 013c80a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/assets/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)
/*-------redraw----*/
//den kallas varje gång datan uppdateras. redrawMap är en boolean
function redraw(redrawMap) {
console.log("redrawing 2");
updateDimensions();

if (redrawMap) {
Expand Down Expand Up @@ -1159,6 +1158,7 @@ function getCountryCenter(countryTopoData) {
}

function animateCountries(countryDict) {
const userPrefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var countries = g.selectAll(".country").filter(c => !!countryDict[c.id]);

setTimeout(() => {
Expand All @@ -1173,12 +1173,16 @@ function getCountryCenter(countryTopoData) {
// .style("transform", "scale(1)");

// fade
countries.transition()
// Only do the bing bong thing if the user doesn't prefer reduced motion
if (!userPrefersReducedMotion) {
countries.transition()
.duration(200)
.style("opacity", "0.8")
.delay((_, i) => i * 100)
.transition().duration(150)
.style("opacity", "1");
}

})
}

Expand Down
8 changes: 8 additions & 0 deletions src/assets/scss/components/_loader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ body.black-theme .loader {
-o-animation: bubblingG 1.3s infinite alternate;
border-radius: 67px;
animation: bubblingG 1.3s infinite alternate;
/* No animation when user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
-moz-animation: none;
-webkit-animation: none;
-ms-animation: none;
-o-animation: none;
animation: none;
}
}
}

Expand Down

0 comments on commit 013c80a

Please sign in to comment.