[components/toc][f]: intersection observer adjsmnt

This commit is contained in:
olayway 2022-05-26 13:01:09 +02:00
parent 90cbf2be8f
commit ac93858d82
4 changed files with 16 additions and 10 deletions

View File

@ -17,7 +17,7 @@ export default function Layout({ children }) {
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" /> <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
</Head> </Head>
<Nav /> <Nav />
<main className="max-w-7xl relative mx-auto px-2 sm:px-6 md:px-8"> <main className="border-2 border-blue-500 max-w-7xl relative mx-auto px-2 sm:px-6 md:px-8">
{/* <div className="hidden md:block w-[16rem] fixed top-16 left-[max(0px,calc(50%-40rem))] bottom-0 right-auto px-8 overflow-y-auto border-2 border-red-500"> */} {/* <div className="hidden md:block w-[16rem] fixed top-16 left-[max(0px,calc(50%-40rem))] bottom-0 right-auto px-8 overflow-y-auto border-2 border-red-500"> */}
{/* <Sidebar /> */} {/* <Sidebar /> */}
{/* </div> */} {/* </div> */}

View File

@ -120,8 +120,7 @@ export default function MdxPage({ children }) {
{ name: "keywords", content: keywords ? keywords : "" }, { name: "keywords", content: keywords ? keywords : "" },
]} ]}
/> />
{/*<article className="px-8 md:pl-[14rem] lg:pr-[1rem] prose max-w-none dark:prose-invert prose-a:break-all mx-auto border-2 border-yellow-500">*/} <article className="border-2 border-green-500 prose dark:prose-invert prose-a:break-all mx-auto lg:mr-[20rem] p-6">
<article className="px-12 lg:pr-[22rem] prose max-w-none dark:prose-invert prose-a:break-all mx-auto">
<header> <header>
<div className="mb-6"> <div className="mb-6">
{title && <h1 className="mb-0">{title}</h1>} {title && <h1 className="mb-0">{title}</h1>}

View File

@ -2,12 +2,18 @@ const getIntersectionObserver = (callback) => {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
return new IntersectionObserver( return new IntersectionObserver(
(entries) => { (entries) => {
entries.forEach((entry) => { const intersectingEntries = entries.filter((e) => e.isIntersecting);
callback(entry); const firstEntry = intersectingEntries[0];
}); if (firstEntry) {
callback(firstEntry);
}
// entries.forEach((entry) => {
// callback(entry);
// });
}, },
{ root: null, { root: null,
rootMargin: `0% 0% -85% 0%` threshold: 0.9,
rootMargin: `0% 0% -90% 0%`
} }
); );
} }

View File

@ -44,15 +44,16 @@ body {
@apply @apply
hidden hidden
lg:block lg:block
w-[22rem] w-[20rem]
p-12 /* 1.5rem */ px-8
pl-12
py-24 py-24
fixed fixed
top-16 top-16
/* bottom-0 */ /* bottom-0 */
right-[max(2rem,calc(50%-40rem+2rem))] right-[max(2rem,calc(50%-40rem+2rem))]
overflow-y-auto overflow-y-auto
border-2
border-red-500
} }
.toc::before { .toc::before {