Fix y-position related processing

This commit is contained in:
Sumire Isshiki 2024-03-11 21:56:31 +09:00
parent 3a1f024a90
commit e36deac343

View File

@ -20,12 +20,7 @@ export default function App() {
const card = Math.max((window.innerHeight / 2) - window.scrollY, 100); const card = Math.max((window.innerHeight / 2) - window.scrollY, 100);
setCardY(card); setCardY(card);
const mutualsElm = document.getElementById("mutuals"); setContentY(card + (window.innerHeight / 2) + 60 * 2);
let mutualsY = 0;
if (mutualsElm) {
mutualsY += mutualsElm.scrollHeight;
}
setContentY(card + (window.innerHeight / 2) + mutualsY * 2);
const cardElm = document.getElementById("card"); const cardElm = document.getElementById("card");
const contentElm = document.getElementById("content"); const contentElm = document.getElementById("content");
@ -45,11 +40,7 @@ export default function App() {
useEffect(() => { useEffect(() => {
handleScroll(); handleScroll();
window.scrollTo(0, 60)
const mutualElm = document.getElementById("mutuals");
if (mutualElm) {
window.scrollTo(0, mutualElm.scrollHeight)
}
window.addEventListener('scroll', handleScroll); window.addEventListener('scroll', handleScroll);
return () => { return () => {
@ -61,11 +52,9 @@ export default function App() {
<RecoilRoot> <RecoilRoot>
<ThemeProvider> <ThemeProvider>
<> <>
<div id="mutuals">
<Mutuals /> <Mutuals />
</div>
<div> <div>
<div className={`sticky h-screen absolute`} style={{ opacity: cardOpacity, marginTop: `${document.getElementById("mutuals")?.offsetHeight}px` }}> <div className={`sticky h-screen`} style={{ opacity: cardOpacity, marginTop: `60px` }}>
<div id="card" className="fixed py-5 -mt-20" style={{ top: `${cardY}px` }}> <div id="card" className="fixed py-5 -mt-20" style={{ top: `${cardY}px` }}>
<Card /> <Card />
</div> </div>