Skip to content

Commit

Permalink
Merge pull request #24 from withgraphite/01-22-fix_nav_fix_clip_path_…
Browse files Browse the repository at this point in the history
…calc

fix(nav): fix clip path calc
  • Loading branch information
shampliu authored Jan 22, 2025
2 parents 811311f + 1c06a82 commit 1b8b3b2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ export default function Nav() {
const commonClassNames = 'px-5 py-1 no-underline '
const activeClassNames = 'text-black'
const [clipPath, setClipPath] = useState({
left: '100',
right: '0'
left: '0%',
right: '100%'
})

const setActivePath = useCallback(p => {
if (ref.current) {
let left = '100',
right = '0'
let left = '0%',
right = '100%'
const idx = LINKS.findIndex(elem => elem.href === p)
if (idx > -1) {
const {offsetLeft, offsetWidth} = ref.current.childNodes[idx]
const {offsetWidth: containerWidth} = ref.current

left = ((offsetLeft * 100) / containerWidth).toFixed()
left = offsetLeft + 'px'
right = (
((containerWidth - (offsetLeft + offsetWidth)) * 100) /
containerWidth
).toFixed()
(containerWidth - (offsetLeft + offsetWidth))
).toFixed() + 'px'
}

setClipPath({
Expand Down Expand Up @@ -88,7 +87,7 @@ export default function Nav() {
<div
className='pointer-events-none absolute left-0 top-0 h-full w-full bg-white transition-[clip-path]'
style={{
clipPath: `inset(0 ${clipPath.right}% 0 ${clipPath.left}%)`
clipPath: `inset(0 ${clipPath.right} 0 ${clipPath.left})`
}}
/>
<div
Expand Down

0 comments on commit 1b8b3b2

Please sign in to comment.