Socket
Socket
Sign inDemoInstall

stacking-order

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stacking-order

Determine which of two elements is in front of the other


Version published
Weekly downloads
2.8K
decreased by-6.65%
Maintainers
1
Install size
5.01 kB
Created
Weekly downloads
 

Changelog

Source

2.0.0

  • Convert to ESM

Readme

Source

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

FAQs

Last updated on 21 Nov 2022

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