Files
fizzy/app/javascript/helpers/sizing_helpers.js
T
2025-10-30 14:00:56 -05:00

12 lines
337 B
JavaScript

export function limitHeightToViewport(el, sizing = true, margin = 64) {
if (!el) return
if (sizing) {
const rect = el.getBoundingClientRect()
const top = Math.max(rect.top, margin)
const max = Math.max(0, window.innerHeight - margin - top)
el.style.maxHeight = `${max}px`
} else {
el.style.maxHeight = ""
}
}