fix: more reliable scroll to top btn initial display + positioning

This commit is contained in:
dragonwocky 2024-01-31 23:04:11 +11:00
parent ba8c660442
commit b55e74a2c5
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
2 changed files with 8 additions and 4 deletions

View File

@ -17,8 +17,9 @@ const setupWrapper = () => {
if (!$help) return; if (!$help) return;
const $wrapper = html`<div const $wrapper = html`<div
class="notion-enhancer--floating-buttons z-50 class="notion-enhancer--floating-buttons z-50
absolute right-0 bottom-[calc(26px+env(safe-area-inset-bottom))] absolute bottom-[calc(26px+env(safe-area-inset-bottom))]
flex gap-[12px] !(&>.notion-help-button:static)" flex gap-[12px] !(&>.notion-help-button:static)"
style="right:${$help.style.right}"
></div>`; ></div>`;
removeMutationListener(addToDom); removeMutationListener(addToDom);
$help.replaceWith($wrapper); $help.replaceWith($wrapper);

View File

@ -25,9 +25,12 @@ export default async (api, db) => {
<//>`, <//>`,
onScroll = () => { onScroll = () => {
if (!$scroller) return; if (!$scroller) return;
const { scrollTop, scrollHeight, clientHeight } = $scroller, const { scrollTop, scrollHeight, clientHeight } = $scroller;
scrollPercent = (scrollTop / (scrollHeight - clientHeight)) * 100, let scrollDist = scrollTop;
scrollDist = scrollUnits === "Percent" ? scrollPercent : scrollTop; if (scrollUnits === "Percent") {
scrollDist = (scrollTop / (scrollHeight - clientHeight)) * 100;
if (isNaN(scrollDist)) scrollDist = 0;
}
if (distanceUntilShown <= scrollDist) addFloatingButton($btn); if (distanceUntilShown <= scrollDist) addFloatingButton($btn);
else removeFloatingButton($btn); else removeFloatingButton($btn);
}, },