Socket
Socket
Sign inDemoInstall

@egstad/detect-motion

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @egstad/detect-motion

A micro ES6 module (~0.5KB) for detecting prefers-reduced-motion and watching for changes.


Version published
Weekly downloads
1
Maintainers
1
Install size
1.08 MB
Created
Weekly downloads
 

Readme

Source

Detect Prefers Reduced Motion 🥴 🔍️ 👀️

A micro ES6 module (~0.5KB) for detecting a users prefers-reduced-motion and watching for changes.

Coverage:statements Coverage:branch Coverage:functions Coverage:lines License: MIT

Installation

npm install @egstad / detect - motion

Usage

import detectMotion from '@egstad/detect-motion'

// watch for `reducedMotionUpdated` events
window.addEventListener('reducedMotionUpdated', (e) => {
    // `e.detail.reduce` returns a boolean
    if (e.detail.reduce) {
        // remove animations here...
    } else {
        // add animations here...
    }
})

// 1. fetch current motion preference
// 2. dispatch result via 'reducedMotionUpdated'
// 3. watch for changes
detectMotion.watch()

Methods

The watch() method is more than likely all you'll need. Here's a list of what each method in the module does.

// 1. fetch current motion preference
// 2. dispatch result via 'reducedMotionUpdated'
detectMotion.get()

// 1. runs `get()`
// 2. adds `reducedMotionUpdated` event listener to window
detectMotion.watch()

// removes `reducedMotionUpdated` event listener from window
detectMotion.destroy()

Example

Here is a screencap demonstrating the realtime updates on Mac OS (System Preferences > Accessibility > Display > Reduce Motion).

Example of changing Prefer Reduced Motion on Mac OS

Keywords

FAQs

Last updated on 09 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc