Currently, I am working on a fascinating NextJS project that showcases a series of interactive blocks. As the user navigates through the app, these blocks dynamically adjust their size and position on the screen.
To achieve this effect, I'm leveraging the power of framer-motion's layout feature. Everything works seamlessly except for one scenario: when users have scrolled down the page, it seems like framer-motion disregards the scroll position and animates the blocks from their original top-of-page location.
If you're curious to see this behavior in action, check out this interactive demo on codesandbox:
- Try selecting the first block without scrolling - notice how it animates flawlessly.
- Now, scroll all the way down and select the last block. You'll observe that instead of animating from its current viewport position, the block appears to animate from beneath the screen.
Is there a workaround to account for the scroll distance so that the animations are tied to the viewport's coordinates rather than the page's top? Your insight would be greatly appreciated!
For visual reference, take a look at this example: