Giter Site home page Giter Site logo

toolness / animated-focus-ring Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 10 KB

Animate the focus ring so keyboard users have an easier time locating it.

Home Page: https://toolness.github.io/animated-focus-ring/

License: The Unlicense

JavaScript 55.33% HTML 44.67%
accessibility javascript

animated-focus-ring's Introduction

This is a simple drop-in script that builds upon the WICG :focus-ring polyfill by adding support for animating the focus ring as it moves around the page.

The behavior is based upon that of the focus ring on the WebAIM website.

This can be useful for keyboard users who might have a difficult time seeing where their focus ring has moved to when they press tab, which can be particularly hard if focusable elements on the page are spaced far apart.

For a live demonstration, see the demo page.

Prerequisites

  • The WICG :focus-ring polyfill.

  • The script also requires support for CSS transitions and a few other APIs present in modern browsers; if they are not supported, the script will simply not enable itself (i.e., it will not "crash").

Usage

Add the animated-focus-ring.js script after the focus-ring.js polyfill. Note that the script must be initialized after the polyfill, or else the animation won't take place.

By default, you don't need to do anything else, so long as you have applied your focus styling to the focus-ring class. When the user presses Tab to move the keyboard focus around the page, the focus ring will appear to "move" from one focused element to another.

Customizing behavior

The script works by creating an absolutely-positioned <div> with the focus-ring and focus-ring-overlay classes; this overlay follows position and size of the focused element, as long as it has the focus-ring class. It becomes transparent when it is done "moving" to a new location.

You can customize the speed and appearance by adding CSS rules targeting the focus-ring-overlay class, e.g.:

.focus-ring-overlay {
  background: rgba(0, 0, 255, 0.25);
  transition: top 0.2s, left 0.2s, width 0.2s, height 0.2s, opacity 0.125s;
}

Note that any transitions you define must animate top, left, width, and height at minimum. If you don't do this, the script will define its own CSS transitions, overriding any that you've defined.

animated-focus-ring's People

Contributors

toolness avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

animated-focus-ring's Issues

Not working in IE 11

If you would use window.pageYOffset and window.pageXOffset instead of window.scrollY and window.scrollX it would also work in IE 11 ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.