amezing/scripts/marquee.js
2026-10-23 09:12:49 -04:00

26 lines
768 B
JavaScript

function updateMarquees() {
document.querySelectorAll(".marquee").forEach((container) => {
const text = container.firstElementChild;
if (!text) return;
const style = getComputedStyle(container);
const paddingLeft = parseFloat(style.paddingLeft);
const paddingRight = parseFloat(style.paddingRight);
const containerInnerWidth =
container.clientWidth - paddingLeft - paddingRight;
const textWidth = text.offsetWidth;
text.style.setProperty("--text-width", `${textWidth}`);
text.style.setProperty("--container-width", `${containerInnerWidth}`);
container.classList.toggle(
"overshoot-row",
textWidth > containerInnerWidth,
);
});
}
window.addEventListener("load", updateMarquees);
window.addEventListener("resize", updateMarquees);