Files

65 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2025-04-18 12:16:11 +03:00
export default class extends HTMLElement {
connectedCallback () {
this.header = document.querySelector('#signing_form_header')
2025-04-23 21:24:18 +03:00
window.addEventListener('scroll', this.onScroll)
window.addEventListener('resize', this.onResize)
2025-04-18 12:16:11 +03:00
2025-04-18 12:28:46 +03:00
if (!this.isNarrow() && this.isHeaderNotVisible()) {
this.showButtons({ animate: false })
}
2025-04-18 12:16:11 +03:00
}
disconnectedCallback () {
2025-04-23 21:24:18 +03:00
window.removeEventListener('scroll', this.onScroll)
window.removeEventListener('resize', this.onResize)
2025-04-18 12:16:11 +03:00
}
2025-04-23 21:24:18 +03:00
onResize = () => {
2025-04-18 12:16:11 +03:00
if (this.isNarrow()) {
this.hideButtons(true)
} else if (this.isHeaderNotVisible()) {
this.showButtons()
}
}
isNarrow () {
2025-04-18 12:28:46 +03:00
return window.innerWidth < 1230
2025-04-18 12:16:11 +03:00
}
2025-04-23 21:24:18 +03:00
onScroll = () => {
2025-04-18 12:16:11 +03:00
if (this.isHeaderNotVisible() && !this.isNarrow()) {
this.showButtons()
} else {
this.hideButtons()
}
}
isHeaderNotVisible () {
const rect = this.header.getBoundingClientRect()
return rect.bottom <= 0 || rect.top >= window.innerHeight
}
2025-04-18 12:28:46 +03:00
showButtons ({ animate } = { animate: true }) {
if (animate) {
this.classList.add('transition-transform', 'duration-300')
}
2025-04-18 12:16:11 +03:00
this.classList.remove('hidden', '-translate-y-10', 'opacity-0')
this.classList.add('translate-y-0', 'opacity-100')
2026-04-17 14:49:14 +03:00
this.inert = false
2025-04-18 12:16:11 +03:00
}
hideButtons () {
this.classList.remove('translate-y-0', 'opacity-100')
this.classList.add('-translate-y-10', 'opacity-0')
2026-04-17 14:49:14 +03:00
this.inert = true
2025-04-18 12:16:11 +03:00
setTimeout(() => {
if (this.classList.contains('-translate-y-10')) {
this.classList.add('hidden')
}
}, 300)
}
}