Animate an element when it scrolls into view
Set up an After Effects animation to animate when it scrolls into view.
As part of our series on After Effects and Lottie in Webflow, we created tiny cardboard box that we animated in After Effects. In this tutorial, we’ll set up the box to animate on the web so it opens when it scrolls into view and close when it scrolls out of view.
We’ll do this in 3 steps:
- Add the animation
- Set up the trigger
- Set up the animation
Add the animation
You’ll need to export your Lottie animation from After Effects and upload it to your Webflow project. We exported the box using Bodymovin. Learn how to do this in steps 3 and 4 of our Full walkthrough tutorial.
For this project, you’ll need to set up two sections — check out our Section tutorial or clone the project.
To find and add the animation, click the photo icon in the Assets panel from the left toolbar and drag the box onto the Canvas between the two sections.
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07bc_5e39eb00352b1438e736db71_HGWjltijXlk8lB7UinQS6TUpbJg9qrmERKQrrq7ZgJUoBT96ESYJgWBUivoLoaAz3l4MYjgQ5HeVnG0V-EoF48rhX0ON_OTQCSrh026mp6BiTjQloNYYM3MJBWXH-y2Uhu7p_bZk.gif)
Because each section is the height of our viewport, let’s size our cardboard box really small (about 100 pixels).
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07b8_5e39eb009e8e9742b6e5bc52_2NzBkcDrGcjXpOZ9R6JVlpgh5a6MIkS02DLniqLU5qlfeWbhDqMCeNl0ECT6UsRCTulRS2KjWvxeEsEpG6vGyD9tGIiBEamPjDirfkbKLQgg_PCRtSJ1Eofpm66LOuqK73rxmRMx.gif)
Step 1 complete! Let’s set up the trigger.
Set up the trigger
Before we add our trigger, we want to make sure the animation (not another element) is selected.
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07b5_5e39eafed0602129e184f755_sfVByr5mbINGSUh3o4bCDpDtwpKgwKl3ERgpmXR6hCOYv25pwJ-ZEH95CPNNzQDQ9DmHfRP0lve_Nd774-yx75eJktsTXcORb-4LYN3K2DaEQLpSWXdC6uCkpDYgA7vD85SV1c8D.gif)
We want the animation to be triggered when the selected element (our Lottie animation, the box) scrolls into view. From the Interactions panel on the right toolbar, open the Element trigger menu and choose Scroll into view.
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07a9_5e39eaffd06021ade584f756_5Xb68WqVdwgC9_h_fGkvHHLNsG48zAHDepN-xe2P5vV9swn1pnzToNdrRGB681By7ETxB0cJ7ANrD0g94LX3mkKSrzfy-qdWPoVc_SIZTvPG0r3qXSbDnqCj-A7ZK3R52BaRhrm-.gif)
Stay put in that Interactions panel to set up the animation in our final step.
Set up the animation
When our selected element scrolls into view, we want the Lottie animation to begin.
From the Interactions panel under When scrolled into view, choose Lottie Playback from the Action menu.
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07a5_5e39eafd414eda9f7c3c2bd6_BgRfcftpS_ySGff7QPHhgt6KQw8Fo7_BHLi9k-3T014gIBMRsoRicsNfBWoHPI2cmYhIIWRDDxinLhddmGDa5m5tPGMlbe8H8TRN77viOhzYD0D3xGvvlhKLTRdTsDxr8FrMYciK.gif)
If we scroll to the top of the page and click preview (the eye in the top left), you’ll see the cardboard box animates open when it’s scrolled into view — just like we’d expect. But if we scroll back up and then down again, the box is still open.
So what we want to do next is set up our Lottie animation to occur and reverse (so the box animates back to being closed) when the box scrolls back out of view. To do this, on the Interactions panel under When scrolled out of view, choose Lottie Playback from the Action menu. And to animate the box back to being closed, choose Reverse.
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07b1_5e39eb02d0602128ee84f76c_0jROW42He2H794ySzoGWvaxV5eV6uuxslq3iau4NcCYb23skZsm05JPwWKBus_Mqplh1V47Q-OeJEEKxhk9xcxYVLRZoF7qYvVQjxQNPTY6TjQbhQ6xIA-cTCwkCx3FQzQp8OwCV.gif)
After all this hard work, we want to make sure this animation isn’t missed — let’s add an offset so the animation isn’t triggered until it hits a certain point on the page. While you’re still in the Interactions panel, add a 10% Offset to both When scrolled into view and When scrolled out of view.
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07a0_5e39eb05feeffa26c4a694db_gqYhSs-CU5ke7uYSbynAkxOKUD1A3z6-hoeCWqf52b6Vw3egaj1EIEgV3qu5WiPh2hz0zE6Liq4pjM1DVd_N6LKTkkRDUT3hN3PQ90TfUphEK0Nus5vrNQMQCafIm_c5bi8L6GDF.gif)
Now when you hit preview, start at the top and scroll a tiny bit, you’ll see the box is closed … until it hits that 10% mark when it animates open. And, if we scroll back to where it’s out of view, when it’s 10% away from being out of view, the animation will play in reverse, just like we told it to. Go us!
![](https://cdn.prod.website-files.com/64949e4863d96e26a1da8386/64b94af088e591e7f60e07ae_5e39eb04d060210d7d84f774_r9Nh6-wjzTZlg_8iUoQ2WHxQu28sw0orf4c7_BosRTspVTFX8jyD19OeU8Hw-PKcmH9gVqYsA8kA5Sgk11NBAC_L9asrL_Rx_6J9VTAuBMRBSjMaWx_yIn_caJLhujIj2gvH7JUG.gif)
We added a Lottie animation, selected our scroll-based trigger, and set up 2 animations: one when it scrolls into view, and another when it scrolls out of view. Which means you just successfully set up an element to animate when it scrolls into and out of view.
High fives all around!