';
return;
}
var lastKey = '';
function setup(){
// 清掉上次克隆出来的副本,只保留第一份
while(inner.children.length > 1){
inner.removeChild(inner.lastChild);
}
var oneW = first.getBoundingClientRect().width; // 一份内容的实际宽度
var wrapW = wrap.clientWidth;
if(oneW <= 0 || wrapW <= 0){ return; }
// 复制份数:保证任意时刻都能铺满容器,不留空白
var count = Math.max(2, Math.ceil(wrapW / oneW) + 1);
for(var i = 1; i < count; i++){
var copy = first.cloneNode(true);
copy.setAttribute('aria-hidden', 'true');
inner.appendChild(copy);
}
// 位移=一份宽度 → 首尾无缝衔接
inner.style.setProperty('--marquee-shift', '-' + oneW.toFixed(1) + 'px');
// 时长=距离/速度 → 速度恒定,与链接数量无关
var duration = Math.max(MIN_DURATION, oneW / SPEED);
inner.style.setProperty('--marquee-duration', duration.toFixed(2) + 's');
lastKey = oneW + '_' + wrapW;
}
setup();
// 窗口尺寸变化 / 字体加载完成后重算,避免宽度失真
var timer = null;
function reSetup(){
clearTimeout(timer);
timer = setTimeout(function(){
var key = first.getBoundingClientRect().width + '_' + wrap.clientWidth;
if(key !== lastKey){ setup(); }
}, 200);
}
window.addEventListener('resize', reSetup);
window.addEventListener('load', setup);
if(document.fonts && document.fonts.ready){
document.fonts.ready.then(setup);
}
})();