class ScrollManager { #windowHeight = 0; #headHeight = 0; #headerHeight = 0; #footerHeight = 0; #actionHeight = 0; #paginationHeight = 0; #container = null; #leftblock = null; #criteria = null; #decision = null; #paddings = 40; #isScrolling = false; #getProperties() { this.#windowHeight = window.innerHeight; const head = document.querySelector('.header'); const footer = document.querySelector('.footer'); const actions = this.#leftblock.querySelector('.actions'); const header = this.#decision.querySelector('.header'); const pagination = this.#decision.querySelector('.pagination'); this.#headHeight = head.getBoundingClientRect().height; this.#footerHeight = footer.getBoundingClientRect().height; this.#actionHeight = actions.getBoundingClientRect().height; this.#headerHeight = header.getBoundingClientRect().height; this.#paginationHeight = pagination.getBoundingClientRect().height; } #changeStyle() { this.#getProperties(); let maxHeight = this.#windowHeight - this.#headerHeight - this.#footerHeight - this.#headHeight - this.#actionHeight - this.#paddings - this.#paginationHeight; //this.#criteria.style.maxHeight = maxHeight + 'px'; //this.#criteria.style.overflowY = 'auto'; //maxHeight += this.#actionHeight; //this.#container.style.maxHeight = maxHeight + 'px'; //this.#container.style.overflowY = 'auto'; } #smoothScrollUpdate() { if (!this.#isScrolling) return; const scrollTop = document.querySelector('.body').scrollTop; if (scrollTop >= this.#headerHeight) { this.#leftblock.style.marginTop = (scrollTop - this.#headerHeight) + 'px'; } else { this.#leftblock.style.marginTop = '0px'; } requestAnimationFrame(() => this.#smoothScrollUpdate()); } constructor() { this.#decision = document.getElementById('decision'); if (!this.#decision) return; this.#leftblock = this.#decision?.querySelector('.app-criteria'); if (!this.#leftblock) return; this.#criteria = this.#leftblock.querySelector('.criteria'); if (!this.#criteria) return; this.#container = this.#decision?.querySelector('.new-app-results-container'); if (!this.#container) return; document.body.addEventListener('resettings', () => this.#changeStyle()); this.#changeStyle(); /*document.querySelector('.body').addEventListener('scroll', () => { if (!this.#isScrolling) { this.#isScrolling = true; this.#smoothScrollUpdate(); } clearTimeout(this.scrollTimeout); this.scrollTimeout = setTimeout(() => { this.#isScrolling = false; }, 100); });*/ } } document.addEventListener('DOMContentLoaded', () => { window.scrollManager = new ScrollManager(); });