Neverending Package Mountain
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    stacking-orderpublic

    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

    var stackingOrder = require( 'stacking-order' );
     
    var a = document.querySelector( '.a' );
    var b = document.querySelector( '.b' );
     
    var order = stackingOrder.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

    Keywords

    none

    install

    npm i stacking-order

    Downloadsweekly downloads

    1

    version

    1.0.0

    license

    MIT

    homepage

    gitlab.com

    repository

    githubgitlab

    last publish

    collaborators

    • avatar