Last active
February 10, 2017 10:58
-
-
Save barneycarroll/531218380e4c6967106accda89950fd3 to your computer and use it in GitHub Desktop.
This file contains 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
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