Skip to content

Instantly share code, notes, and snippets.

@colecmc
Last active June 1, 2016 21:29
Show Gist options
  • Save colecmc/c8a11c8c2eceb23b23af3ee272bc8619 to your computer and use it in GitHub Desktop.
Save colecmc/c8a11c8c2eceb23b23af3ee272bc8619 to your computer and use it in GitHub Desktop.
Gets highest z-index and adds 10 or adds number specified in parameter. Use this method sparingly as it can be a slow operation, potentially locking up the UI.
/**
* @version 1.0.0
* @author (@colecmc)
* @param {number} incrementBy
* @returns {number}
* Gets highest z-index and adds 10 or adds number specified in parameter.
* Use this method sparingly as it can be a slow operation, potentially locking up the UI.
* Map over ALL elements to find the z-indexes.
* Filter out the elements where z-index is 'auto'.
* Reduce remaining elements down to the highest value, then add 10.
*/
const getNextHighestZindex = (incrementBy = 10) => Swlxws.ToArray(SWLXWS_DOC.getElementsByTagName('*'))
.map(item => getComputedStyle(item, null).getPropertyValue('z-index'))
.filter(item => item !== 'auto')
.reduce((pre, cur) => Math.max(pre, cur)) + incrementBy;
/** \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment