diff --git a/gatsby-browser.tsx b/gatsby-browser.tsx index 9fa6c42..5478107 100644 --- a/gatsby-browser.tsx +++ b/gatsby-browser.tsx @@ -22,10 +22,22 @@ export const shouldUpdateScroll = ({ pathname, }) => { if (pathname.startsWith('/photogallery/') && pathname !== '/photogallery/' ) { - console.log('scroll to image') - requestAnimationFrame(() => { - window.scrollTo(0, 180); - }) + // if (prevRouterProps?.location.pathname === '/photogallery/') { + // console.log('scroll to image from gallery') + // // setTimeout(() => { + + // // window.scrollTo(0, 0); + // // }, 100) + // setTimeout(() => { + // window.scrollTo(0, 180); + // }, 10) + // } else { + // console.log('scroll to image from elsewhere') + // requestAnimationFrame(() => { + // window.scrollTo(0, 180); + // }) + // } + console.log('gallery image, skipping') return false; } if (prevRouterProps?.location.pathname === pathname) { diff --git a/src/components/GalleryImage/GalleryImage.js b/src/components/GalleryImage/GalleryImage.js index d6fe34d..6af6433 100644 --- a/src/components/GalleryImage/GalleryImage.js +++ b/src/components/GalleryImage/GalleryImage.js @@ -63,6 +63,12 @@ const GalleryImage = ({ data, location: { state } }) => { setIsClient(true); }, []); + useEffect(() => { + requestAnimationFrame(() => { + window.scrollTo(0, 180); + }); + }, [image.base]); + const nextIndex = sortedImageList && currentIndex < sortedImageList.length ? currentIndex + 1 diff --git a/src/pages/photogallery.tsx b/src/pages/photogallery.tsx index eebd6e5..6d7fa1e 100644 --- a/src/pages/photogallery.tsx +++ b/src/pages/photogallery.tsx @@ -94,7 +94,7 @@ const GalleryPage = ({ } navigate( getGalleryPageUrl({ sortKey, keyword: filterKeyword, showDebug }, ""), - { replace: true, state: { suppressAutoscroll: true } } + // { replace: false } ); window.removeEventListener("scroll", removeHash); }, @@ -126,7 +126,7 @@ const GalleryPage = ({ }); setTimeout(() => { window.addEventListener("scroll", removeHash); - }, 900) + }, 100) }); }, [ hash, diff --git a/src/styles/global.css b/src/styles/global.css index 28c194c..7ce3147 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -10,7 +10,7 @@ box-sizing: border-box; } :root { - scroll-behavior: smooth; + /* scroll-behavior: smooth; */ } /* .hero * { transition: color .2s, background-color .2s;