stacking-order

2.0.0 • Public • Published

stacking-order

Determine which of two nodes appears in front of the other.

Why?

The stacking order rules are fairly complex. Determining whether node A will render in front of node B involves much more than comparing the z-index of the two nodes – you have to consider their parents, and which of them create new stacking contexts, which in turn depends on CSS properties like opacity, transform, mix-blend-mode and various others that you probably hadn't considered.

The tie-breaker, if that doesn't yield a conclusive answer, is the position in the document (with later nodes rendering in front of earlier nodes).

Installation

npm install --save stacking-order

...or grab a copy from npmcdn.com/stacking-order.

Usage

import { compare } from 'stacking-order';

const a = document.querySelector('.a');
const b = document.querySelector('.b');

const order = compare(a, b);
// -> `1` if a is in front of b, `-1` otherwise

Bugs

It's entirely possible that the algorithm used here doesn't exactly match the spec. If you find a bug, please raise an issue after reading CONTRIBUTING.md. Thanks!

License

MIT


made by @rich_harris

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    1,052
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    1,052
  • 1.0.1
    1,458
  • 1.0.0
    5

Package Sidebar

Install

npm i stacking-order

Weekly Downloads

2,515

Version

2.0.0

License

MIT

Unpacked Size

5.13 kB

Total Files

3

Last publish

Collaborators

  • rich_harris