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 Handbook: The Ultimate Guide to ScrollTrigger in WordPress

When transitioning a pixel-perfect Figma design into a live production environment, the biggest failure point for most developers is the scroll experience. A premium digital product does not treat scrolling as a basic utility to move down a document; it treats scrolling as the user’s steering wheel for a cinematic journey.

If you want to command top-tier agency pricing, you must master spatial web design. You need the ultimate guide to ScrollTrigger in WordPress.

By pairing the mathematical precision of GSAP (GreenSock Animation Platform) with the bare-metal DOM architecture of Bricks Builder, you can completely hijack the native scrollbar. In this expert guide, we will break down the mechanics of ScrollTrigger, solve advanced pinning interactions, and engineer 60fps web animation that elevates your WordPress platforms to absolute luxury standards.

The Spatial Web: Why Standard Scrolling is Dead

Look at the highest-converting digital experiences on the web today. They don’t just dump information onto the screen. They control the pacing of the narrative.

When a user scrolls, they shouldn’t just be moving past static blocks of text. Elements should scale into view, background layers should parallax at fractional speeds, and key value propositions should pin themselves to the center of the screen, demanding attention before releasing the user to continue.

This is called “Scrollytelling.” It lowers cognitive load by ensuring the user’s eye is only ever focused on one heavily curated piece of information at a time. To achieve this, we rely entirely on GSAP’s ScrollTrigger plugin.

The Structural Advantage: Bricks Builder + GSAP

Executing complex ScrollTrigger logic requires a pristine environment.

If you attempt to write advanced pinning animations inside a legacy page builder (like Elementor), you will fail. When ScrollTrigger pins an element, it calculates the exact height, padding, and margins of that DOM node. Legacy builders wrap your simple text elements in up to six layers of invisible <div> containers. This “Div Soup” severely confuses the JavaScript engine, causing layout thrashing, incorrect calculations, and a stuttering mobile experience.

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 1-to-1 reflection of your intended architecture, GSAP can target the exact DOM node instantly, offloading the heavy math to the device’s GPU for a flawless 60fps execution.

Core Mechanics: How ScrollTrigger Maps the DOM

Before writing code, you must understand how ScrollTrigger thinks. It maps the relationship between two points on your element and two points on the user’s viewport.

  • The Trigger: The specific HTML element that ScrollTrigger is watching.

  • The Start: Defines when the animation begins. start: "top 80%" means the animation fires when the top of your trigger element hits 80% down the user’s screen.

  • ToggleActions vs. Scrub:

    • Use toggleActions: "play none none reverse" if you want an element to fade in and play at its own speed once triggered.

    • Use scrub: true (or scrub: 1 for a one-second smoothing delay) to physically tie the animation’s playback head to the user’s scrollbar. If they stop scrolling, the animation pauses.

Code Execution: Pinning a Fixed, Transparent Background

Let’s look at a highly specific, real-world architectural challenge.

When engineering spatial interfaces—such as the background blur animations developed for the Ark Career Explorer project—a common requirement is ensuring background images remain transparent and fixed during specific scroll interactions while foreground content moves past them.

Amateurs try to solve this with CSS background-attachment: fixed, which causes severe repainting bugs and jumping on iOS Safari. The elite solution is using ScrollTrigger to physically pin a transparent layer to the DOM.

Here is the flawless JavaScript architecture for Bricks Builder:

document.addEventListener("DOMContentLoaded", () => {
  // Register the plugin
  gsap.registerPlugin(ScrollTrigger);

  // Use gsap.context for strict Bricks memory management
  let ctx = gsap.context(() => {
    
    // The Goal: Pin a transparent background layer while foreground content scrolls
    const bgLayer = document.querySelector(".fixed-transparent-bg");
    const scrollSection = document.querySelector(".foreground-scroll-section");

    if (bgLayer && scrollSection) {
      ScrollTrigger.create({
        trigger: scrollSection,
        start: "top top", // When the top of the section hits the top of the viewport
        end: "bottom bottom", // Unpin when the bottom of the section arrives
        pin: bgLayer, // Pin the background element
        pinSpacing: false, // Do not add artificial padding; let foreground overlap
        
        // Ensure the background remains visually transparent and stable during the pin
        onEnter: () => gsap.set(bgLayer, { backgroundColor: "rgba(0,0,0,0)" }),
        
        // Optional: Scrub a blur effect as the user scrolls
        animation: gsap.to(bgLayer, { 
            backdropFilter: "blur(12px)", 
            ease: "none" 
        }),
        scrub: true
      });
    }

  }); // End Context
});

By utilizing pinSpacing: false, we instruct GSAP to lock the background in place without forcing the subsequent HTML elements further down the page. The foreground effortlessly glides over the locked, transparent background.

Real-World Masterclasses: Auditing the Elite

To command premium authority, you must benchmark your work against the highest standards.

Recently, while conducting a comprehensive UI/UX audit and optimization report for tea-moments.com to meet luxury market benchmarks, it became glaringly obvious that static layouts destroy brand perception. Luxury brands (like Apple, Rolex, or high-end boutique teas) rely heavily on spatial depth.

They use ScrollTrigger to orchestrate intricate sequences: a product image scales down, the background crossfades, and typography masks itself onto the screen—all synchronized to a single scroll motion. Implementing this level of web animation transforms a digital brochure into a highly tactile, premium product.

Comparative Table: CSS Scroll vs. GSAP ScrollTrigger

To visualize the ROI of this architectural upgrade, review this matrix:

Technical Metric CSS Scroll-Timeline (Experimental) GSAP ScrollTrigger Architecture Agency & UX Impact
Browser Support 🔴 Highly limited (Fails on older iOS) 🟢 Universal (Bulletproof polyfills) Reliability: Guarantees every user sees the premium experience.
Pinning Mechanics 🔴 Requires messy position: sticky hacks 🟢 Native pin: true math Flawless Layouts: No jumping or broken mobile viewports.
Animation Logic 🟡 Basic linear progression 🟢 Advanced (Scrubbing, Snapping, Callbacks) Cinematic Flow: Allows for complex storytelling sequences.
DOM Execution 🟢 Native 🟢 Surgically targets Bricks HTML Performance: Maintains peak Core Web Vitals and 60fps rendering.

FAQ: Mastering ScrollTrigger in WordPress

Q1: How do I handle responsive ScrollTriggers for mobile devices? A: Pinning complex sections on a mobile phone often feels claustrophobic and breaks the thumb-scrolling experience. You must use gsap.matchMedia(). Wrap your complex desktop ScrollTrigger inside an mm.add("(min-width: 992px)", () => { ... }) block. For mobile screens, you can write a simpler, unpinned fade-up animation. GSAP will automatically destroy the heavy desktop math when the user rotates their device or resizes the browser.

Q2: Why are my ScrollTrigger markers overlapping or calculating the wrong heights? A: This happens if elements on your page load dynamically after GSAP has calculated the DOM (e.g., lazy-loaded images without explicit heights, or custom web fonts loading late). To fix this, always ensure your images in Bricks Builder have explicit width and height attributes. Alternatively, you can call ScrollTrigger.refresh() after your fonts or heavy assets have fully loaded.

Q3: Does pinning an element conflict with Bricks Builder’s native smooth scrolling? A: Yes, it can, if not configured properly. If you are using Bricks’ native smooth scroll or a library like Lenis, you must sync ScrollTrigger’s internal ticker with the smooth scroller’s requestAnimationFrame. Furthermore, if you are using PJAX (AJAX page loading), ensure your ScrollTriggers are wrapped in gsap.context() so you can call ctx.revert() to kill old scroll markers before the new page renders.

Conclusion & The Architect’s Next Steps

Mastering the ultimate guide to ScrollTrigger in WordPress fundamentally shifts your identity from a web designer to a spatial frontend architect.

You are no longer constrained by the 2D limitations of a web browser. By combining the bare-metal, semantic HTML of Bricks Builder with the limitless physics engine of GSAP, you take absolute control over time and space. You dictate exactly what the user sees, exactly when they see it, and exactly how it feels.

Stop building pages. Start engineering experiences.

Your next practical step: Open your local development environment. Create a Hero section in Bricks with a transparent background layer and a foreground text layer. Enqueue the GSAP core and ScrollTrigger, and run the pinning JavaScript provided in this guide. Once you feel that background lock perfectly into place as you scroll, your entire approach to web architecture will evolve.