Files
web_hgtv_h5/app/static/js/squarePromo.js
T
谢宇宁andClaude Opus 5.5 3639d2184a Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:47:17 +07:00

47 lines
1.5 KiB
JavaScript

(function () {
function setupRoot(root) {
var track = root.querySelector(".square-promo__track");
var group = root.querySelector(".square-promo__group");
if (!track || !group) return;
var clone = root.querySelector(".square-promo__group--clone");
if (clone) clone.remove();
root.classList.remove("is-marquee");
track.style.animationDuration = "";
if (group.scrollWidth <= root.clientWidth + 1) return;
clone = group.cloneNode(true);
clone.classList.add("square-promo__group--clone");
clone.setAttribute("aria-hidden", "true");
clone.querySelectorAll("a").forEach(function (link) {
link.setAttribute("tabindex", "-1");
});
track.appendChild(clone);
root.classList.add("is-marquee");
track.style.animationDuration =
Math.max(18, Math.round(group.scrollWidth / 36)) + "s";
if (typeof window.initLazyImages === "function") {
window.initLazyImages(clone);
}
}
function setupAll() {
document.querySelectorAll("[data-square-promo]").forEach(setupRoot);
}
var resizeTimer = 0;
function onResize() {
window.clearTimeout(resizeTimer);
resizeTimer = window.setTimeout(setupAll, 160);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", setupAll, { once: true });
} else {
setupAll();
}
window.addEventListener("resize", onResize);
})();