aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbyUtils.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-24 18:44:37 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-24 20:10:50 +0800
commitac66fd66dfe20c91588afaa4837fd046b32c27ee (patch)
tree853cceb902d5e7246720ac823d51551404287af6 /src/dumbyUtils.mjs
parentbd1c1973e31354d9effccae5f1bf7f4f16e13bdd (diff)
feat: improve focus utils
* use block height to determine behavior of scrollIntoView() * change color of indicator for focused block * make indicator always visible
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r--src/dumbyUtils.mjs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs
index ba0bbf8..fc9eab9 100644
--- a/src/dumbyUtils.mjs
+++ b/src/dumbyUtils.mjs
@@ -49,7 +49,10 @@ export function focusNextBlock(reverse = false) {
49 const nextBlock = blocks[nextIndex] 49 const nextBlock = blocks[nextIndex]
50 blocks.forEach(b => b.classList.remove('focus')) 50 blocks.forEach(b => b.classList.remove('focus'))
51 nextBlock?.classList?.add('focus') 51 nextBlock?.classList?.add('focus')
52 nextBlock.scrollIntoView({ behavior: 'smooth', block: "nearest" }) 52 const scrollBlock = nextBlock.getBoundingClientRect().height > nextBlock.parentElement.getBoundingClientRect().height * 0.8
53 ? 'nearest'
54 : 'center'
55 nextBlock.scrollIntoView({ behavior: 'smooth', block: scrollBlock })
53} 56}
54 57
55export function removeBlockFocus() { 58export function removeBlockFocus() {