Last active
October 9, 2022 08:33
-
-
Save perrysmotors/45b1edd5e0b57e059048d3f9337c9560 to your computer and use it in GitHub Desktop.
Make a layer stick after a fixed scroll distance in Framer X
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
import { Override, motionValue, useTransform } from "framer" | |
// Create a MotionValue to track scroll content offset | |
const contentOffsetY = motionValue(0) | |
// Apply this override to your scroll component | |
export function TrackScroll(): Override { | |
return { | |
contentOffsetY: contentOffsetY, | |
} | |
} | |
// Apply this override to your header component | |
export function StickyHeader(): Override { | |
const travel = 400 | |
const y = useTransform( | |
contentOffsetY, | |
[0, -travel, -travel * 2], | |
[0, 0, travel], | |
{ | |
clamp: false, | |
} | |
) | |
return { | |
y: y, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment