Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active February 10, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/531218380e4c6967106accda89950fd3 to your computer and use it in GitHub Desktop.
Save barneycarroll/531218380e4c6967106accda89950fd3 to your computer and use it in GitHub Desktop.
const div = document.createElement('div')
const div_w0 = div.cloneNode()
const div_w100 = div.cloneNode()
const div_flex = div.cloneNode()
div_w0.style.marginRight = '-100%'
div_w0.style.visibility = 'hidden'
div_w0.style.width = '100%'
div_w0.setAttribute('aria-hidden', true)
div_w100.style.width = '100%'
div_flex.style.display = 'flex'
div_flex.style.position = 'relative'
function matchHeights([...els]){
els.forEach(matchHeight)
}
function matchHeight(subject, {}, siblings){
const container = div_flex.cloneNode()
siblings.forEach(el => {
const clone = el.cloneNode(true)
const wrapper = (
el === subject
? div_w100 : div_w0
).cloneNode()
wrapper.appendChild(clone)
container.appendChild(wrapper)
})
subject.parentNode.replaceChild(container, subject)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment