fix: 구 sidebar 코드 제거

This commit is contained in:
2021-12-08 01:01:25 +09:00
parent df0c8b3c92
commit e07b64339a
+6 -47
View File
@@ -43,69 +43,28 @@ $(function ($) {
(() => { (() => {
let finInit = false; let finInit = false;
const objects: {
target: HTMLElement,
button: HTMLAnchorElement,
}[] = [];
let nationMsgBox!: HTMLElement; let nationMsgBox!: HTMLElement;
let nationMsg!: HTMLElement; let nationMsg!: HTMLElement;
let nationMsgHeight: number | undefined = undefined; let nationMsgHeight: number | undefined = undefined;
function init() { function init() {
const buttons = document.querySelectorAll<HTMLAnchorElement>('#float-tabs a.btn'); if(finInit){
if (!buttons) { return false;
}
const _nationMsgBox = document.getElementById('nation-msg-box');
if (!_nationMsgBox) {
return false; return false;
} }
finInit = true; finInit = true;
for (const button of buttons) { nationMsgBox = _nationMsgBox;
const targetQuery = button.href.split('#');
if (!targetQuery || targetQuery.length < 2) {
continue;
}
const target = document.getElementById(targetQuery[1]);
if (!target) {
continue;
}
objects.push({ target, button });
}
nationMsgBox = unwrap(document.getElementById('nation-msg-box'));
nationMsg = unwrap(document.getElementById('nation-msg')); nationMsg = unwrap(document.getElementById('nation-msg'));
} }
function onScroll() { function onScroll() {
if (!finInit && !init()) return; if (!finInit && !init()) return;
for (const { button } of objects) {
button.classList.remove('active');
}
const screenHeight = window.innerHeight
for (const { target, button } of objects) {
const { top, bottom, height } = target.getBoundingClientRect();
if (top >= 0 && bottom <= screenHeight) {
//valid
}
else if (top <= 0 && bottom >= screenHeight) {
//valid
}
else if (top < 0) {
if (bottom / height < 0.8) {
continue;
}
}
else if (bottom > screenHeight) {
if ((screenHeight - top) / height < 0.8) {
continue;
}
}
button.classList.add('active');
}
if (nationMsgBox.offsetWidth < nationMsg.offsetWidth) { if (nationMsgBox.offsetWidth < nationMsg.offsetWidth) {
if (nationMsgHeight === undefined) { if (nationMsgHeight === undefined) {
nationMsgHeight = nationMsgBox.offsetHeight; nationMsgHeight = nationMsgBox.offsetHeight;