Skip to content

Commit 395e16a

Browse files
author
Taois
committed
feat: 主题
1 parent d51ee4a commit 395e16a

1 file changed

Lines changed: 30 additions & 32 deletions

File tree

dashboard/src/components/VideoGrid.vue

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -539,28 +539,30 @@ const handleScroll = (e) => {
539539
};
540540
541541
const checkTextOverflow = () => {
542-
// 简化的文本溢出检查,确保浏览器兼容性
543542
if (isProcessing || updateCount >= MAX_UPDATES_PER_SECOND) {
544543
return;
545544
}
546-
547-
try {
548-
const titleElements = document.querySelectorAll('.title-text');
549-
if (titleElements && titleElements.length > 0) {
545+
546+
requestAnimationFrame(() => {
547+
try {
548+
const titleElements = containerRef.value?.querySelectorAll('.title-text') || [];
550549
titleElements.forEach(element => {
551-
if (element && element.scrollWidth && element.clientWidth) {
552-
// 只检查,不修改DOM,避免触发重排
553-
const hasOverflow = element.scrollWidth > element.clientWidth;
554-
if (hasOverflow) {
555-
// 可以在这里添加一些简单的样式类,但不修改内容
556-
element.setAttribute('title', element.textContent || '');
557-
}
550+
element.removeAttribute('data-overflow');
551+
element.style.removeProperty('--title-marquee-distance');
552+
553+
const wrapperWidth = element.parentElement?.clientWidth || element.clientWidth;
554+
const overflowDistance = element.scrollWidth - wrapperWidth;
555+
element.setAttribute('title', element.textContent || '');
556+
557+
if (overflowDistance > 2) {
558+
element.style.setProperty('--title-marquee-distance', `${overflowDistance}px`);
559+
element.setAttribute('data-overflow', 'true');
558560
}
559561
});
562+
} catch (error) {
563+
console.error('checkTextOverflow error:', error);
560564
}
561-
} catch (error) {
562-
console.error('checkTextOverflow error:', error);
563-
}
565+
});
564566
};
565567
566568
onMounted(() => {
@@ -589,6 +591,7 @@ onMounted(() => {
589591
// 延迟检查内容高度,确保数据已经渲染
590592
setTimeout(() => {
591593
checkContentHeight();
594+
checkTextOverflow();
592595
}, 1000);
593596
}
594597
} catch (error) {
@@ -616,6 +619,7 @@ if (ENABLE_BASIC_UPDATES) {
616619
resizeTimer = setTimeout(() => {
617620
if (!isProcessing && containerRef.value) {
618621
updateScrollAreaHeight();
622+
setTimeout(checkTextOverflow, 100);
619623
}
620624
}, 800); // 增加延迟,减少频率
621625
};
@@ -689,6 +693,7 @@ watch([() => props.videos, () => props.showStats], ([newVideos, newShowStats]) =
689693
console.log('Videos updated:', newVideos.length);
690694
// 检查内容高度
691695
checkContentHeight();
696+
checkTextOverflow();
692697
// 延迟检查高度恢复,确保内容已经渲染完成
693698
setTimeout(() => {
694699
checkHeightRestore();
@@ -913,39 +918,32 @@ defineExpose({
913918
transition: color 0.2s ease;
914919
margin: 0;
915920
width: 100%;
921+
min-width: 0;
916922
display: block;
917-
}
918-
919-
/* 普通状态下隐藏溢出文本 */
920-
.title-text:not([data-overflow="true"]) {
921923
overflow: hidden;
922924
text-overflow: ellipsis;
923925
}
924926
925-
/* 跑马灯效果 - 电子公告屏幕样式 */
926927
.title-text[data-overflow="true"] {
927-
animation: marquee 10s linear infinite;
928-
animation-delay: 1s;
929928
width: max-content;
929+
max-width: none;
930930
min-width: 100%;
931+
overflow: visible;
932+
text-overflow: clip;
933+
animation: title-marquee 10s linear 0.8s infinite;
934+
will-change: transform;
931935
}
932936
933937
.title-text[data-overflow="true"]:hover {
934938
animation-play-state: paused;
935939
}
936940
937-
@keyframes marquee {
938-
0% {
939-
transform: translateX(0);
940-
}
941-
15% {
941+
@keyframes title-marquee {
942+
0%, 12% {
942943
transform: translateX(0);
943944
}
944-
85% {
945-
transform: translateX(calc(-100% + 100px));
946-
}
947-
100% {
948-
transform: translateX(calc(-100% + 100px));
945+
70%, 100% {
946+
transform: translateX(calc(-1 * var(--title-marquee-distance, 0px)));
949947
}
950948
}
951949

0 commit comments

Comments
 (0)