Created
July 15, 2019 09:01
-
-
Save xto3na/9867a2e50d3ac4948ce5fdeb38bc3044 to your computer and use it in GitHub Desktop.
Set Same Height
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
export function setSameHeight(selector) { // Делает высоту всех элементов по селектору как у самого высокого | |
let arrayOfElements = document.querySelectorAll(selector); | |
let maxHeight = 0; | |
if(arrayOfElements.length > 0) { | |
for(let i = arrayOfElements.length - 1; i >= 0; i--) { | |
let heightOfElement = arrayOfElements[i].getBoundingClientRect().height; | |
if(maxHeight < heightOfElement) { | |
maxHeight = heightOfElement; | |
} | |
} | |
arrayOfElements.forEach((element) => { | |
element.style.height = maxHeight + 'px'; | |
}); | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment