Last active
July 15, 2016 09:30
-
-
Save gwwar/2f661deec7b99a1a418b to your computer and use it in GitHub Desktop.
Given a node, returns the closest stacking context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getClosestStackingContext( node ) { | |
if( ! node || node.nodeName === 'HTML' ) { | |
console.log( node, 'has stacking context, reason: root' ); | |
return document.documentElement; | |
} | |
const computedStyle = getComputedStyle( node ); | |
if ( computedStyle.position === 'fixed' ) { | |
console.log( node, 'has stacking context, reason: position: fixed' ); | |
return node; | |
} else if ( computedStyle.zIndex !== 'auto' && computedStyle.position !== 'static' ) { | |
console.log( node, `has stacking context, reason: zindex: ${ computedStyle.zIndex } and position: ${ computedStyle.position }` ); | |
return node; | |
} else if ( computedStyle.opacity !== '1' ) { | |
console.log( node, `has stacking context, reason: opacity: ${ computedStyle.opacity }` ); | |
return node; | |
} else if ( computedStyle.transform !== 'none' ) { | |
console.log( node, `has stacking context reason: transform: ${ computedStyle.transform }` ); | |
return node; | |
} else if ( computedStyle.mixBlendMode !== 'normal' ) { | |
console.log( node, `has stacking context, reason: mix-blend-mode: ${ computedStyle.mixBlendMode }`); | |
return node; | |
} else if ( computedStyle.filter !== 'none' ) { | |
console.log( node, `has stacking context, reason: filter: ${ computedStyle.filter }` ); | |
return node; | |
} else if ( computedStyle.isolation === 'isolate' ) { | |
console.log( node, 'has stacking context, reason: isolation: isolate' ); | |
return node; | |
} else if ( computedStyle.webkitOverflowScrolling === 'touch' ) { | |
console.log( node, 'has stacking context, reason: -webkit-overflow-scrolling: touch' ); | |
return node; | |
} else { | |
return getClosestStackingContext( node.parentNode ); | |
} | |
} |
Author
gwwar
commented
Dec 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment