Files
scud_ai/modules/web_api/static/js/chat/scroll.js
T

48 lines
1.8 KiB
JavaScript

/**
* ===============================================================================
* FILE: modules/web_api/static/js/chat/scroll.js
* ROLE: Изолированный движок скролла чата (Gemini-style scroll to top).
* ===============================================================================
*/
window.scrollToUserMessageTop = function() {
const container = document.getElementById("chat-messages-container");
if (!container) return;
// Обеспечиваем невидимый эластичный спейсер в конце ленты
let spacer = document.getElementById("chat-scroll-spacer");
if (!spacer) {
spacer = document.createElement("div");
spacer.id = "chat-scroll-spacer";
spacer.style.height = "calc(100vh - 220px)";
spacer.style.flexShrink = "0";
spacer.style.pointerEvents = "none";
container.appendChild(spacer);
} else {
container.appendChild(spacer);
}
const userBubbles = container.querySelectorAll(".user-chat-bubble");
const targetEl = userBubbles[userBubbles.length - 1];
if (!targetEl) return;
setTimeout(() => {
const containerRect = container.getBoundingClientRect();
const targetRect = targetEl.getBoundingClientRect();
const targetScrollTop = container.scrollTop + (targetRect.top - containerRect.top) - 16;
container.scrollTo({
top: Math.max(0, targetScrollTop),
behavior: 'smooth'
});
}, 40);
};
window.ensureScrollSpacerAtEnd = function() {
const container = document.getElementById("chat-messages-container");
const spacer = document.getElementById("chat-scroll-spacer");
if (container && spacer) {
container.appendChild(spacer);
}
};