Skip to content

Instantly share code, notes, and snippets.

@xto3na
Created July 15, 2019 09:01
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 xto3na/9867a2e50d3ac4948ce5fdeb38bc3044 to your computer and use it in GitHub Desktop.
Save xto3na/9867a2e50d3ac4948ce5fdeb38bc3044 to your computer and use it in GitHub Desktop.
Set Same Height
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