Created
October 9, 2021 07:19
-
-
Save Ankhena/f14cc31225ec48ae8d859c162d706fd2 to your computer and use it in GitHub Desktop.
equalHeight vanilla javascript
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 equalHeight = (selector) => { | |
const blocks = document.querySelectorAll(selector); | |
let maxHeight = 0; | |
let blockHight; | |
blocks.forEach(block => { | |
block.style.setProperty('height', 'unset'); | |
}) | |
blocks.forEach(block => { | |
blockHight = block.clientHeight; | |
if (blockHight > maxHeight) { | |
maxHeight = blockHight; | |
} | |
}) | |
blocks.forEach(block => { | |
block.style.setProperty('height', maxHeight + 'px'); | |
}) | |
} | |
equalHeight('.element'); | |
window.addEventListener('resize', () => { | |
equalHeight('.element'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment