height_equaler.js 592 B

1234567891011121314151617181920212223242526272829303132
  1. export class height_equaler {
  2. #to;
  3. #from;
  4. constructor(from, to) {
  5. this.#from = from;
  6. this.#to = to;
  7. this.#set_styles();
  8. new ResizeObserver(() => {
  9. this.#update();
  10. }).observe(from);
  11. setTimeout(() => {
  12. this.#update();
  13. }, 100);
  14. }
  15. get height() {
  16. return this.#from.offsetHeight;
  17. }
  18. #set_styles() {
  19. this.#to.style.height = "0px";
  20. this.#to.style.transition = "height 0.5s";
  21. }
  22. #update() {
  23. this.#to.style.height = this.height + "px";
  24. }
  25. }