aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-02 15:07:01 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-02 15:07:01 +0800
commit045e55ce0547544e064f09f87bd1f75d7fa088b0 (patch)
tree7170010388ddaaf3be7cab647f427ad398bf4b5a /src/utils.mjs
parent061a9e7de3f3426225f73e3cbd59942c1ceae2c8 (diff)
feat: prevent menu show outside of window
Diffstat (limited to 'src/utils.mjs')
-rw-r--r--src/utils.mjs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/utils.mjs b/src/utils.mjs
index d9ed2d7..c9a2457 100644
--- a/src/utils.mjs
+++ b/src/utils.mjs
@@ -87,3 +87,10 @@ export function throttle (func, delay) {
87 return func.call(context, ...args) 87 return func.call(context, ...args)
88 } 88 }
89} 89}
90
91export const shiftByWindow = element => {
92 const rect = element.getBoundingClientRect()
93 const offsetX = window.innerWidth - rect.left - rect.width
94 const offsetY = window.innerHeight - rect.top - rect.height
95 element.style.transform = `translate(${offsetX < 0 ? offsetX : 0}px, ${offsetY < 0 ? offsetY : 0}px)`
96}