Skip to content

Commit e041223

Browse files
committed
Handle prefers-reduced-motion changes
1 parent ba8652e commit e041223

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sparkly-text.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ class SparklyText extends HTMLElement {
9494
);
9595
this.addSparkles();
9696
}
97+
98+
motionOK.addEventListener("change", this.motionOkChange);
99+
}
100+
101+
disconnectedCallback() {
102+
motionOK.removeEventListener("change", this.motionOkChange);
103+
}
104+
105+
// Declare as an arrow function to get the appropriate 'this'
106+
motionOkChange = () => {
107+
if (motionOK.matches) {
108+
this.addSparkles();
109+
}
97110
}
98111

99112
addSparkles() {

0 commit comments

Comments
 (0)