Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class HeightGroup {
  2. constructor(els) {
  3. this.nodeArray = [...els]
  4. this.nodeHeights
  5. this.newHeight
  6. }
  7.  
  8. matchHeights() {
  9. this.nodeHeights = []
  10. this.newHeight = null
  11.  
  12. this.nodeArray.forEach(node => {
  13. node.style.minHeight = ''
  14. this.nodeHeights.push(node.offsetHeight)
  15. })
  16.  
  17. this.newHeight = Math.max.apply(null, this.nodeHeights)
  18.  
  19. this.nodeArray.forEach(node => {
  20. node.style.minHeight = `${this.newHeight}px`
  21. })
  22. }
  23.  
  24. watchElements() {
  25. window.addEventListener('resize', this.matchHeights)
  26. this.matchHeights()
  27. }
  28.  
  29. destroy() {
  30. window.removeEventListener('resize', this.matchHeights)
  31. this.nodeArray.forEach(node => {
  32. node.style.minHeight = ''
  33. })
  34. }
  35. }
  36.  
  37. export default HeightGroup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement