Staggered Animations in Webflow: A Step-by-Step Tutorial

Published on
January 5, 2023

How to Create Staggered Animations in Webflow

Webflow's interaction tools are incredibly powerful, allowing you to create engaging and dynamic animations for your website. However, one limitation that users often encounter is the inability to stagger animations on page load. In this tutorial, we'll walk through a workaround that allows you to achieve staggered animations using Webflow's interface and a bit of custom JavaScript.

Setting up the Elements in Webflow

First, let's start by setting up the elements in Webflow that we want to animate. In this example, we have four objects with different colors, which we'll refer to as "zag" objects. These will serve as the basis for our staggered animations.

  1. Create the Objects: Within your Webflow project, add the "zag" objects to your canvas. Make sure they are distinct and identifiable from one another.

  2. Add Interaction Trigger: Select each "zag" object and add an interaction trigger. For this example, we'll use "Mouse Click" or "Tap" as the trigger, but you can modify this based on your specific requirements.

  3. Create the Initial Animation: Within the interaction panel, start by adding a new animation for each "zag" object. We'll name the animation "Zag Rotate" for clarity.

Creating the Animations in Webflow

Now, let's dive into creating the animations for the "zag" objects. We'll set up a basic rotation animation to demonstrate the staggered effect.

  1. Initial Animation: For the "Zag Rotate" animation, add a rotation action to the object. Set the rotation to 30 degrees on the Z-axis, and apply an "ease in out" transition.

  2. Duplicate the Animation: Duplicate the animation timeline and modify the rotation to -30 degrees after a specified time, such as two seconds. This will create a back-and-forth rotation effect for each "zag" object.

  3. Enable Looping: With the animations set, enable looping for each object's interaction. This ensures that the rotation animation repeats continuously.

  4. Testing the Animations: Preview the animations to ensure that each "zag" object rotates continuously and independently when triggered.

Staggering the Animations with JavaScript

While the animations are working individually, the challenge arises when we want to stagger their start times to avoid overlapping. To achieve this, we'll use custom JavaScript to automatically trigger each animation at specific intervals.

  1. Identifying the Elements: Make a note of the classes or IDs assigned to each "zag" object in Webflow. We'll use these identifiers to target and trigger the animations using JavaScript.

  2. Adding Custom JavaScript: In your Webflow project, go to the page settings and locate the custom code section. Here, we'll add a script to automate the staggering of our animations.

// Staggered Animation Scriptdocument.addEventListener("DOMContentLoaded", function() {  setTimeout(function() {    document.querySelector('.zag1').click();  }, 500);  setTimeout(function() {    document.querySelector('.zag2').click();  }, 1000);  // Repeat for other "zag" objects});

In the above script, we're using the querySelector method to target each "zag" object based on its class and triggering a click event after a defined delay. This simulates the staggered start for our animations.

  1. Testing the Staggered Animations: Once the script is added, publish the website and observe the staggered animations taking effect on page load. You should see each "zag" object rotate at its own time, creating a visually appealing staggered animation effect.

Preventing User Interference with CSS

One potential issue with the automated staggered animations is that users can accidentally trigger the animations again when interacting with the objects. To prevent this, we can use CSS to make the objects unclickable after the animations begin.

  1. Applying CSS Styles: Add the following CSS code to the page's custom code section to make the "zag" objects unclickable once the animations start.
<style>  .zag-lines {    pointer-events: none;  }</style>

In the above code, we're targeting a parent div with the class "zag-lines" and setting its pointer events to none. This effectively disables any clicking or interaction with the "zag" objects once the animations begin.

  1. Review and Refine: After applying the CSS, test the animations again to ensure that user interaction doesn't disrupt the staggered animation sequence. Users should no longer be able to interfere with the animations once they begin.

Conclusion

By following this tutorial, you've learned how to create staggered animations in Webflow using a combination of Webflow's interaction tools and custom JavaScript. Staggered animations can add a dynamic and engaging element to your website, capturing the attention of visitors and enhancing the overall user experience. Experiment with different timing intervals and animation properties to achieve the desired visual effects for your web projects using Webflow's intuitive interface and the flexibility of custom code.