From 858f7139ffd844b78ee0452941fdb7c29edc4b5d Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 8 Dec 2021 01:01:25 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B5=AC=20sidebar=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/main.ts | 53 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) diff --git a/hwe/ts/main.ts b/hwe/ts/main.ts index 528e1836..9377d259 100644 --- a/hwe/ts/main.ts +++ b/hwe/ts/main.ts @@ -43,69 +43,28 @@ $(function ($) { (() => { let finInit = false; - const objects: { - target: HTMLElement, - button: HTMLAnchorElement, - }[] = []; let nationMsgBox!: HTMLElement; let nationMsg!: HTMLElement; let nationMsgHeight: number | undefined = undefined; function init() { - const buttons = document.querySelectorAll('#float-tabs a.btn'); - if (!buttons) { + if(finInit){ + return false; + } + const _nationMsgBox = document.getElementById('nation-msg-box'); + if (!_nationMsgBox) { return false; } finInit = true; - for (const button of buttons) { - 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')); + nationMsgBox = _nationMsgBox; nationMsg = unwrap(document.getElementById('nation-msg')); } function onScroll() { 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 (nationMsgHeight === undefined) { nationMsgHeight = nationMsgBox.offsetHeight;