Skip to content

Commit

Permalink
feat: add smooth transition to header on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleJKC authored and lxchapu committed Jul 15, 2024
1 parent bd9d4e3 commit 596d8b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/header/HeaderContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function HeaderMenu({ isBgShow }: { isBgShow: boolean }) {

return (
<nav
className={clsx('relative rounded-full group pointer-events-auto', {
className={clsx('relative rounded-full group pointer-events-auto duration-100', {
'shadow-lg shadow-zinc-800/5 border border-primary bg-white/50 dark:bg-zinc-800/50 backdrop-blur':
isBgShow,
})}
Expand Down
8 changes: 5 additions & 3 deletions src/components/header/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import { pageScrollLocationAtom, pageScrollDirectionAtom } from '@/store/scrollI
import { isMobileAtom } from '@/store/viewport'
import { floor } from 'lodash-es'

const threshold = 50
const threshold = 60

export function useHeaderBgOpacity() {
const scrollY = useAtomValue(pageScrollLocationAtom)
if (scrollY >= threshold) {
if (scrollY >= threshold * 2) {
return 1
} else if (scrollY <= threshold) {
return 0
} else {
return floor(scrollY / threshold, 2)
return floor((scrollY - threshold) / threshold, 2)
}
}

Expand Down

0 comments on commit 596d8b3

Please sign in to comment.