1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-22 08:42:44 +01:00
Minecraft-Phantom-Panel/Server/Phantom.Server.Web/Shared/InstanceLog.razor.js
2022-10-07 17:21:39 +02:00

35 lines
680 B
JavaScript

// noinspection JSUnusedGlobalSymbols
let log;
let shouldAutoScroll = false;
let isAutoScrolling = false;
export function initLog() {
log = document.getElementById("log");
if (log) {
shouldAutoScroll = true;
log.scrollTop = log.scrollHeight;
log.addEventListener("scroll", function() {
if (isAutoScrolling) {
isAutoScrolling = false;
}
else {
setTimeout(function() {
shouldAutoScroll = log.scrollHeight - log.scrollTop - log.clientHeight < 5;
}, 10);
}
});
}
else {
console.error("Missing log element.");
}
}
export function scrollLog() {
if (shouldAutoScroll) {
isAutoScrolling = true;
log.scrollTop = log.scrollHeight;
}
}