generated from sarioglu/svelte-tailwindcss-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #625 from intechstudio/feat/DisabledAnimations
🚩PR: Added setting of Disable Animations
- Loading branch information
Showing
5 changed files
with
136 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
export const reduced_motion_store = create_reduced_motion_store(); | ||
|
||
function create_reduced_motion_store() { | ||
// Grab the prefers reduced media query. | ||
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)"); | ||
const reduced = !mediaQuery || mediaQuery.matches; //true if reduced | ||
const store = writable(reduced); | ||
|
||
// Ads an event listener to check for changes in the media query's value. | ||
mediaQuery.addEventListener("change", () => { | ||
store.set(mediaQuery.matches); | ||
}); | ||
return store; | ||
} | ||
|
||
export function setDocumentAnimationsEnabled(value: boolean) { | ||
if (value) { | ||
enableAnimation(); | ||
} else { | ||
disableAnimation(); | ||
} | ||
} | ||
|
||
function disableAnimation() { | ||
const css = ` | ||
* { | ||
animation-duration: 0.01ms !important; | ||
animation-iteration-count: 1 !important; | ||
transition-duration: 0.01ms !important; | ||
animation-delay: 0.01ms !important; | ||
} | ||
`; | ||
const existingStyleElement = document.getElementById("custom-global-style"); | ||
if (!existingStyleElement) { | ||
const styleElement = document.createElement("style"); | ||
styleElement.textContent = css; | ||
styleElement.id = "custom-global-style"; | ||
document.head.appendChild(styleElement); | ||
} | ||
} | ||
|
||
function enableAnimation() { | ||
const existingStyleElement = document.getElementById("custom-global-style"); | ||
if (existingStyleElement) { | ||
existingStyleElement.remove(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters