Skip to content

Commit f4fab93

Browse files
authored
fix(resource): stack scroll-to-top button above share bar and fix long note jump to comments (#462)
1 parent 29fce9a commit f4fab93

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎resources/js/components/resources/NoteReader.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const goToNext = () => {
6868
class="group"
6969
>
7070
<div
71-
class="overflow-hidden rounded-2xl border border-slate-200/90 bg-white shadow-xs transition hover:border-slate-300 hover:shadow-md dark:border-gray-800 dark:bg-gray-900"
71+
class="min-h-[260px] overflow-hidden rounded-2xl border border-slate-200/90 bg-slate-100/70 shadow-xs transition hover:border-slate-300 hover:shadow-md sm:min-h-[380px] dark:border-gray-800 dark:bg-gray-900"
7272
>
7373
<img
7474
:src="item.url || item.source"

‎resources/js/pages/Resource.vue‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,39 @@ const scrollToComments = () => {
231231
232232
const el = document.getElementById('comments');
233233
234-
if (el) {
235-
el.scrollIntoView({ behavior: 'smooth' });
234+
if (!el) {
235+
return;
236236
}
237+
238+
el.scrollIntoView({ behavior: 'smooth' });
239+
240+
// For long multi-image notes (e.g. 50+ images), lazy image layout shifts
241+
// can cause the initial smooth scroll destination to fall short.
242+
// We poll and readjust until the comments section is within the viewport.
243+
let attempts = 0;
244+
const adjustScroll = () => {
245+
attempts++;
246+
const target = document.getElementById('comments');
247+
248+
if (!target) {
249+
return;
250+
}
251+
252+
const rect = target.getBoundingClientRect();
253+
254+
// If comments is still below the viewport bottom
255+
if (rect.top > window.innerHeight) {
256+
target.scrollIntoView({
257+
behavior: attempts > 1 ? 'auto' : 'smooth',
258+
});
259+
260+
if (attempts < 12) {
261+
setTimeout(adjustScroll, 250);
262+
}
263+
}
264+
};
265+
266+
setTimeout(adjustScroll, 300);
237267
};
238268
239269
const totalCommentsCount = computed(() => {
@@ -787,7 +817,7 @@ onUnmounted(() => {
787817
@click="scrollToTop"
788818
title="উপরে যান"
789819
aria-label="Scroll to top"
790-
class="fixed right-4 bottom-[calc(4.5rem+env(safe-area-inset-bottom)+0.5rem)] z-50 flex h-9.5 w-9.5 cursor-pointer items-center justify-center rounded-full bg-slate-900/90 text-white shadow-lg ring-1 ring-black/10 backdrop-blur-xs transition duration-150 hover:scale-105 hover:bg-indigo-600 active:scale-95 sm:right-6 sm:bottom-6 sm:h-10 sm:w-10 dark:bg-gray-800/90 dark:text-gray-100 dark:ring-white/10 dark:hover:bg-indigo-600 dark:hover:text-white"
820+
class="fixed right-4 bottom-[8.5rem] z-50 flex h-9.5 w-9.5 cursor-pointer items-center justify-center rounded-full bg-slate-900/90 text-white shadow-lg ring-1 ring-black/10 backdrop-blur-xs transition duration-150 hover:scale-105 hover:bg-indigo-600 active:scale-95 sm:right-6 sm:bottom-20 sm:h-10 sm:w-10 dark:bg-gray-800/90 dark:text-gray-100 dark:ring-white/10 dark:hover:bg-indigo-600 dark:hover:text-white"
791821
>
792822
<ArrowUp class="h-4 w-4 stroke-[2.3]" />
793823
</button>

0 commit comments

Comments
 (0)