summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/sticky-sidebar.ts
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-03-09 14:28:01 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-03-09 14:28:01 +0900
commitbe7e3b9a0cb81b78a744993fef2fa2fd2833fa9c (patch)
treec82e18ce93ec0a24c57d7e36eb54a09266b3a25b /packages/frontend/src/scripts/sticky-sidebar.ts
parentenhnace(frontend): 文字列比較のためのローマナイズを強化(... (diff)
downloadmisskey-be7e3b9a0cb81b78a744993fef2fa2fd2833fa9c.tar.gz
misskey-be7e3b9a0cb81b78a744993fef2fa2fd2833fa9c.tar.bz2
misskey-be7e3b9a0cb81b78a744993fef2fa2fd2833fa9c.zip
refactor(frontend): scripts -> utility
Diffstat (limited to 'packages/frontend/src/scripts/sticky-sidebar.ts')
-rw-r--r--packages/frontend/src/scripts/sticky-sidebar.ts55
1 files changed, 0 insertions, 55 deletions
diff --git a/packages/frontend/src/scripts/sticky-sidebar.ts b/packages/frontend/src/scripts/sticky-sidebar.ts
deleted file mode 100644
index 50f1e6ecc8..0000000000
--- a/packages/frontend/src/scripts/sticky-sidebar.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SPDX-FileCopyrightText: syuilo and misskey-project
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-export class StickySidebar {
- private lastScrollTop = 0;
- private container: HTMLElement;
- private el: HTMLElement;
- private spacer: HTMLElement;
- private marginTop: number;
- private isTop = false;
- private isBottom = false;
- private offsetTop: number;
- private globalHeaderHeight = 59;
-
- constructor(container: StickySidebar['container'], marginTop = 0, globalHeaderHeight = 0) {
- this.container = container;
- this.el = this.container.children[0] as HTMLElement;
- this.el.style.position = 'sticky';
- this.spacer = document.createElement('div');
- this.container.prepend(this.spacer);
- this.marginTop = marginTop;
- this.offsetTop = this.container.getBoundingClientRect().top;
- this.globalHeaderHeight = globalHeaderHeight;
- }
-
- public calc(scrollTop: number) {
- if (scrollTop > this.lastScrollTop) { // downscroll
- const overflow = Math.max(0, this.globalHeaderHeight + (this.el.clientHeight + this.marginTop) - window.innerHeight);
- this.el.style.bottom = null;
- this.el.style.top = `${-overflow + this.marginTop + this.globalHeaderHeight}px`;
-
- this.isBottom = (scrollTop + window.innerHeight) >= (this.el.offsetTop + this.el.clientHeight);
-
- if (this.isTop) {
- this.isTop = false;
- this.spacer.style.marginTop = `${Math.max(0, this.globalHeaderHeight + this.lastScrollTop + this.marginTop - this.offsetTop)}px`;
- }
- } else { // upscroll
- const overflow = this.globalHeaderHeight + (this.el.clientHeight + this.marginTop) - window.innerHeight;
- this.el.style.top = null;
- this.el.style.bottom = `${-overflow}px`;
-
- this.isTop = scrollTop + this.marginTop + this.globalHeaderHeight <= this.el.offsetTop;
-
- if (this.isBottom) {
- this.isBottom = false;
- this.spacer.style.marginTop = `${this.globalHeaderHeight + this.lastScrollTop + this.marginTop - this.offsetTop - overflow}px`;
- }
- }
-
- this.lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
- }
-}