diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-24 18:44:37 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-24 20:10:50 +0800 |
commit | ac66fd66dfe20c91588afaa4837fd046b32c27ee (patch) | |
tree | 853cceb902d5e7246720ac823d51551404287af6 /src/dumbyUtils.mjs | |
parent | bd1c1973e31354d9effccae5f1bf7f4f16e13bdd (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.mjs | 5 |
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 | ||
55 | export function removeBlockFocus() { | 58 | export function removeBlockFocus() { |