Skip to content

Commit 66b1cc2

Browse files
authored
Merge pull request #515 from BeAPI/fix/miwin-reduce-motion
Mixins `reduced-motion` / `allows-motion`
2 parents ad852c6 + 459d1ac commit 66b1cc2

2 files changed

Lines changed: 31 additions & 24 deletions

File tree

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
/**
2-
* Reduced-motion for animations
2+
* Motion preference helpers for animations
33
*
4-
* @author Paolo Tesei
4+
* Driven by `html.js-animation` / `html.no-js-animation` (toggled from
5+
* prefers-reduced-motion in header.php, and by the a11y access config plugin).
56
*
6-
* @param $reduce
7+
* @author Paolo Tesei
78
*
89
* Examples :
910
*
1011
* @include reduced-motion { ... }
11-
* return @media screen and (prefers-reduced-motion : reduce) { ... }
12-
*
13-
* you can add heavy animation using :
12+
* → html.no-js-animation & { ... }
13+
* → html.no-js-animation { ... } when used at root / inside :root or html
1414
*
15-
* @include reduced-motion (false) { ... }
16-
* return @media screen and (prefers-reduced-motion : no-preference) { ... }
15+
* @include allows-motion { ... }
16+
* → html.js-animation & { ... }
17+
* → html.js-animation { ... } when used at root / inside :root or html
1718
*
1819
*/
1920

20-
@mixin reduced-motion($reduce: true) {
21-
@if ($reduce == true) {
22-
@media screen and (prefers-reduced-motion: reduce) {
21+
@mixin _html-animation-class($class) {
22+
// `:root` and `html` are the same element as the animation class host, so they
23+
// cannot appear as descendants of `html.#{$class}`.
24+
$parent: "#{&}";
25+
26+
@if not & or $parent == ":root" or $parent == "html" {
27+
@at-root html.#{$class} {
2328
@content;
2429
}
2530
} @else {
26-
@media screen and (prefers-reduced-motion: no-preference) {
31+
html.#{$class} & {
2732
@content;
2833
}
2934
}
3035
}
36+
37+
// Styles when motion is reduced (`html.no-js-animation`).
38+
@mixin reduced-motion {
39+
@include _html-animation-class("no-js-animation") {
40+
@content;
41+
}
42+
}
43+
44+
// Styles when animations are allowed (`html.js-animation`).
45+
@mixin allows-motion {
46+
@include _html-animation-class("js-animation") {
47+
@content;
48+
}
49+
}

‎src/scss/03-base/_variables-css.scss‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,11 @@
4343
--paragraph--line-height-small: 1.4;
4444
--paragraph--line-height-default: 1.4;
4545

46-
/*
47-
* Animation speeds
48-
*/
49-
--speed: 1s;
50-
5146
/*
5247
* Admin bar
5348
*/
5449
--wp-admin-bar-height: var(--wp-admin--admin-bar--height, 0rem);
5550

56-
/*
57-
* A11y reduced motion
58-
*/
59-
@include reduced-motion {
60-
--speed: 0s;
61-
}
62-
6351
/*
6452
* Global breakpoints
6553
*/

0 commit comments

Comments
 (0)