function updateHeaderHeight() {
        // Get the height of #brx-header
        const headerHeight = document.querySelector('#brx-header').offsetHeight;
          
        // Store the height in the CSS custom property --header-height
        document.documentElement.style.setProperty('--brxw-header-height', headerHeight + 'px');
    }

    // Execute the function as soon as the document is ready
    document.addEventListener('DOMContentLoaded', function() {
        updateHeaderHeight();  // Initial update of header height when the document is ready

        // Update the header height on window resize and orientation change
        window.addEventListener('resize', updateHeaderHeight);
        window.addEventListener('orientationchange', updateHeaderHeight);
});

The Architect’s Guide: A ScrollTrigger Animation Tutorial for Beginners in Bricks Builder

When you first transition from assembling basic templates to architecting custom digital experiences, you quickly realize that static layouts are no longer enough. To capture attention and command top-tier agency pricing, you must control the pacing of the narrative. You need motion.

If you want to graduate from basic CSS fade-ins to cinematic, scroll-driven experiences, you are in the right place. Welcome to the definitive ScrollTrigger animation tutorial for beginners.

By pairing the mathematical precision of GSAP (GreenSock Animation Platform) with the bare-metal DOM architecture of Bricks Builder, you can engineer 60fps web animation that feels tactile, expensive, and deliberate. In this WordPress masterclass, we will bypass the confusing jargon. I will show you exactly how to map your HTML elements to the user’s scrollbar, write your first flawless interaction, and set a foundation for elite frontend architecture.

The Shift: From Static Pages to Interactive Web Animation

Amateur web designers view scrolling simply as a way for users to reach the bottom of a document. Frontend architects view scrolling as a steering wheel.

When you use basic WordPress plugins to add an “entrance animation,” the element usually fires independently of the user. It fades in blindly. But when you use GSAP’s ScrollTrigger, the animation is context-aware. An image doesn’t just scale up; it scales up because the user scrolled down. If the user scrolls back up, the image scales back down.

This creates a spatial web experience. It lowers cognitive load by ensuring the user’s eye is always drawn to exactly what you want them to see, exactly when you want them to see it.

Why GSAP and Bricks Builder? The Perfect WordPress Setup

Before writing a single line of code, we must respect the environment.

If you attempt a ScrollTrigger animation tutorial for beginners inside a legacy page builder (like Elementor or Divi), you will run into the “Div Soup” bottleneck. These builders wrap a simple text block in five layers of invisible <div> containers. When ScrollTrigger attempts to calculate the height and position of your element, it gets confused by the bloated wrappers. Your animations will glitch, and your mobile performance will tank.

Bricks Builder is the ultimate canvas. It outputs pure, semantic HTML. A section is a <section>. A container is a <div>.

Because Bricks provides a pristine DOM structure, GSAP can target the exact HTML node instantly. It offloads the heavy math directly to the device’s GPU, guaranteeing buttery-smooth web animation.

Core Concepts: How ScrollTrigger Actually Works

ScrollTrigger is not magic; it is simply collision detection. To write your first animation, you only need to understand three core concepts:

  1. The Trigger: The HTML element you want the browser to watch.

  2. The Start: The collision point. You define an invisible line on the element and an invisible line on the viewport (your screen). When these two lines cross, the animation fires.

  3. The End: The point where the animation logic concludes.

For example, start: "top 80%" translates to: “Start the animation when the TOP of my trigger element hits the line that is 80% down the screen.”

Step 1: Preparing Your Bricks Builder Canvas (Clean DOM)

Let’s translate theory into execution. Open your Bricks Builder editor. We are going to build a simple grid of feature cards that elegantly slide up as you scroll to them.

  1. Create the Structure: Add a Section, and inside it, add a Block set to CSS Grid (3 columns).

  2. Add the Cards: Place three Divs inside your grid to act as your feature cards. Add some basic text and styling to them.

  3. Assign the Target Class: We need a way for our JavaScript to find these cards. Select all three cards and type .gsap-reveal-card into the Bricks CSS class input.

Architect’s Note: Always use a prefix like .gsap- for your animation targets. It tells anyone reading your code that this class is tied to the JavaScript engine, not just visual styling.

Step 2: Writing Your First ScrollTrigger (The JavaScript)

Now, we write the logic. Whether you place this in your Bricks Child Theme /js folder or use the Bricks Builder Custom Code footer settings, the architecture remains the same. (Ensure you have loaded GSAP Core and ScrollTrigger via CDN first!).

Here is the pristine, memory-safe code for your first animation:

document.addEventListener("DOMContentLoaded", () => {
  // 1. Register the plugin so GSAP knows it exists
  gsap.registerPlugin(ScrollTrigger);

  // 2. Use gsap.context() to establish professional memory management
  let ctx = gsap.context(() => {
    
    // Select all the cards we built in Bricks
    const cards = document.querySelectorAll('.gsap-reveal-card');

    // Loop through each card and apply the ScrollTrigger logic
    cards.forEach((card) => {
      
      gsap.from(card, {
        y: 100, // Start 100px pushed down
        opacity: 0, // Start invisible
        duration: 1, // Take 1 second to animate to its natural position
        ease: "power3.out", // A premium deceleration curve
        
        // The ScrollTrigger Magic
        scrollTrigger: {
          trigger: card, // Watch this specific card
          start: "top 85%", // Fire when the card's top hits 85% down the viewport
          markers: true, // Turn this to 'false' before launching! It shows the collision lines.
          toggleActions: "play none none reverse" // Play down, reverse up
        }
      });
      
    });

  }); // End Context
});

When you load the front end of your site, you will see exactly how the power3.out math creates a luxury, decelerating motion as the cards enter the viewport.

Step 3: Scrubbing vs. ToggleActions (Controlling Playback)

In the code above, we used toggleActions. This tells ScrollTrigger to act like a switch: when the lines cross, play the animation at its normal 1-second duration.

But what if you want the animation tied directly to the speed of the user’s thumb? This is called Scrubbing.

If you replace toggleActions: "play none none reverse" with scrub: 1, the behavior changes entirely. The animation will no longer play on its own. Instead, it links physically to the scrollbar. If the user scrolls down quickly, the card flies up. If they stop scrolling halfway, the card freezes halfway transparent. The 1 adds a one-second smoothing delay so the motion feels fluid, not jerky.

This is how enterprise sites achieve cinematic “Scrollytelling.”

Real-World Masterclasses: Sites Using Premium ScrollTrigger

To understand the business value of a properly engineered GSAP timeline, look at how top-tier brands operate:

  1. Apple (Product Pages): Apple defines the standard for 60fps web motion. They rely heavily on scrub: true. As you scroll down an iPhone page, a phone render will rotate and scale flawlessly in sync with your scroll wheel.

  2. Stripe: Their landing pages use subtle toggleActions. Elements don’t pop into view; they glide upward with strict mathematical timing, maintaining the user’s focus on the copywriting and creating immense brand trust.

By implementing the exact code provided in this guide, you have adopted the identical motion physics used by elite digital agencies.

Comparative Table: Basic Scroll Plugins vs. GSAP ScrollTrigger

To visualize the sheer power of this architectural upgrade, review this matrix:

Technical Metric CSS / Basic WP Animation Plugins GSAP ScrollTrigger Architecture Agency & UX Impact
Motion Physics 🟑 Basic Linear/Ease Transitions 🟒 Advanced Math (Power3, Inertia) Premium Vibe: Transforms a template into a bespoke digital product.
Scroll Awareness 🟑 Fires once when in viewport 🟒 Deeply integrated (Scrubbing, Pinning) Immersive UX: Connects the user physically to the interface.
DOM Requirements 🟑 Works on bloated builders 🟒 Demands clean HTML (Bricks Builder) Performance: Maintains peak Core Web Vitals and prevents lag.
Debugging πŸ”΄ Impossible to see trigger points 🟒 Visual markers: true system Development Speed: Eliminates guesswork during QA testing.

FAQ: Troubleshooting ScrollTrigger in WordPress

Q1: How do I see the ScrollTrigger markers during development? A: This is a lifesaver for beginners. Inside your scrollTrigger: {} configuration object, simply add markers: true. GSAP will inject visual lines on the right side of your screen showing exactly where your “Start” and “End” collision points are. (Always remember to remove this before pushing the site live!)

Q2: Why does my animation jump or glitch on mobile devices? A: Mobile browsers (like Safari on iOS) hide their URL address bar as you scroll down. This changes the physical height of the viewport, forcing ScrollTrigger to recalculate everything dynamically, causing a jump. To fix this, place ScrollTrigger.config({ ignoreMobileResize: true }); at the very top of your JavaScript file.

Q3: Where do I put my custom JavaScript in Bricks Builder? A: As a beginner, the easiest place is in the Bricks Editor. Go to Settings (Gear Icon) -> Page Settings -> Custom Code, and paste your code into the Body (footer) scripts box. Make sure you wrap your code in <script></script> tags! As you advance to a professional workflow, you will move this code into a dedicated .js file inside your Bricks Child Theme.

Conclusion & The Architect’s Next Steps

Executing a ScrollTrigger animation tutorial for beginners is a defining moment in your career.

You have moved beyond the limitations of visual toggle menus. By combining the bare-metal, semantic HTML of Bricks Builder with the boundless physics engine of GSAP, you have taken absolute control over the browser. You are no longer building static WordPress pages; you are engineering fluid, unforgettable web animation experiences.

Stop accepting the default fade-in. Take control of the user’s journey.

Your next practical step: Open a local Bricks Builder environment. Recreate the 3-card grid from Step 1, add the .gsap-reveal-card class, and run the JavaScript provided in Step 2. Turn markers: true on, and slowly scroll up and down your page. Once you see the exact moment the math executes natively on your screen, your standard for web design will change forever.