Skip to content

Instantly share code, notes, and snippets.

@perrysmotors
Last active October 9, 2022 08:33
Show Gist options
  • Save perrysmotors/45b1edd5e0b57e059048d3f9337c9560 to your computer and use it in GitHub Desktop.
Save perrysmotors/45b1edd5e0b57e059048d3f9337c9560 to your computer and use it in GitHub Desktop.
Make a layer stick after a fixed scroll distance in Framer X
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