-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sticky header an astro component
- Loading branch information
Showing
3 changed files
with
40 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
import type { CollectionEntry } from 'astro:content' | ||
interface Props { | ||
post: CollectionEntry<'blog'> | ||
} | ||
const { post } = Astro.props | ||
--- | ||
|
||
<header | ||
id="sticky-header" | ||
class="inset-x-0 items-center backdrop-blur-sm bg-[hsla(0,0%,100%,.8)] dark:bg-white-reversed/50 flex h-[50px] justify-between px-8 fixed z-[90] top-[-50px] opacity-0 data-[hydrated=true]:opacity-100" | ||
> | ||
<div class="flex flex-row justify-between w-full items-center"> | ||
<div class="overflow-hidden text-ellipsis whitespace-nowrap text-slate-800 dark:text-white leading-[1.3] mr-4 text-sm font-bold"> | ||
{post.data.title} | ||
</div> | ||
</div> | ||
|
||
<div class="bg-[#e6e6e6] dark:bg-slate-600 bottom-[-2px] h-[2px] left-0 absolute w-full"> | ||
<div id="progress-indicator" class="bg-orange-400 h-full origin-[0%] scale-x-0" /> | ||
</div> | ||
</header> | ||
|
||
<script> | ||
import { animate, scroll } from 'motion' | ||
|
||
// Start showing and moving the sticky header until 100px offset. | ||
scroll(animate('#sticky-header', { x: 0, y: 50, opacity: [0, 1] }), { | ||
offset: ['start start', '100px'], | ||
}) | ||
|
||
// Animate scroll indicator depending on the window scroll position | ||
scroll(animate('#progress-indicator', { scaleX: ['0', '1'] }), { | ||
offset: ['100px', 'end end'], | ||
}) | ||
</script> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters