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 Blueprint: A Step-by-Step Guide to Writing GSAP Code in Bricks Builder

When it comes to high-end web animation, there is a distinct visual threshold that separates a standard template from a world-class digital product. Standard websites use basic CSS fade-ins. Premium websites use physics. They use mathematical deceleration, spatial masking, and scroll-linked timelines to guide the user’s eye with cinematic precision.

To achieve this level of elite interaction in WordPress, you cannot rely on bloated visual plugins. You need the GreenSock Animation Platform (GSAP). But GSAP is only as fast as the HTML it manipulates.

If you want to command top-tier agency pricing and build 60fps experiences, this is your definitive step-by-step guide to writing GSAP code in Bricks Builder. By pairing the undisputed king of JavaScript animation with the cleanest DOM architecture in the WordPress ecosystem, you will transform static Figma designs into breathtaking, hardware-accelerated realities. Let’s build your foundation.

Why Bricks Builder and GSAP are the Ultimate Tech Stack for Web Animation

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

If you attempt writing GSAP code in Bricks Builder‘s competitors—like Elementor or Divi—you will immediately encounter the “Div Soup” problem. To render a simple text heading, legacy builders wrap your text in 4 to 6 unnecessary <div> layers. When GSAP tries to animate that heading, it forces the browser’s CPU to recalculate the geometry of every single wrapper 60 times a second. This causes layout thrashing, dropped frames, and laggy animations.

Bricks Builder is engineered differently. It outputs bare-metal HTML. If you add a Heading element and give it a class of .hero-title, the frontend output is strictly <h1 class="hero-title">.

This semantic purity allows GSAP to target DOM nodes with surgical precision. It offloads the animation transforms (x, y, scale) directly to the GPU, guaranteeing buttery-smooth web animation even on older mobile processors.

Step 1: Preparing the WordPress Environment (Proper Enqueuing)

The amateur way to load GSAP is by pasting a CDN link into a “Header Scripts” plugin. Do not do this. It causes render-blocking issues and destroys your SEO.

The professional way is to use the native WordPress enqueue system via your Bricks Child Theme’s functions.php file. This ensures the library loads securely in the footer.

Insert this code into your child theme’s functions.php:

<?php
/**
 * Enqueue GSAP Core, Plugins, and Custom Scripts
 */
function pixloop_architect_enqueue_gsap() {
    // 1. Load GSAP Core in the footer
    wp_enqueue_script( 'gsap-core', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js', array(), null, true );

    // 2. Load ScrollTrigger (Depends on GSAP Core)
    wp_enqueue_script( 'gsap-scrolltrigger', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollTrigger.min.js', array('gsap-core'), null, true );

    // 3. Load your bespoke animation file (Cache busted with filemtime)
    $js_path = '/js/main-animations.js';
    if ( file_exists( get_stylesheet_directory() . $js_path ) ) {
        wp_enqueue_script( 'custom-gsap', get_stylesheet_directory_uri() . $js_path, array('gsap-core', 'gsap-scrolltrigger'), filemtime( get_stylesheet_directory() . $js_path ), true );
    }
}
add_action( 'wp_enqueue_scripts', 'pixloop_architect_enqueue_gsap' );

Step 2: Architecting a Clean DOM in Bricks Builder

Now, open the Bricks Builder visual editor. We need to set up the HTML targets for our JavaScript.

Imagine a Hero Section with a main headline, a subheadline, and a button.

  1. Select your Section container. Add a CSS class: .hero-section.

  2. Select your main Heading. Add a CSS class: .gsap-hero-title.

  3. Select your Paragraph text. Add a CSS class: .gsap-hero-text.

  4. Select your Button. Add a CSS class: .gsap-hero-btn.

By using the .gsap- prefix, any developer reviewing your site immediately knows these elements are tied to your JavaScript physics engine.

Step 3: Writing Your First GSAP Animation (The JavaScript)

Create the main-animations.js file inside the /js folder of your Bricks child theme. This is where we write the logic.

In modern WordPress architecture, we always wrap our GSAP code inside gsap.context(). This provides automatic garbage collection, preventing memory leaks if your site uses Bricks’ AJAX page transitions.

document.addEventListener("DOMContentLoaded", () => {
  // Register plugins to prevent tree-shaking errors
  gsap.registerPlugin(ScrollTrigger);

  // Initialize Memory-Safe Context
  let ctx = gsap.context(() => {
    
    // Create a Master Timeline for the Hero Section
    const heroTl = gsap.timeline({
      defaults: { ease: "power4.out" } // A premium, cinematic deceleration curve
    });

    // Animate the elements sequentially
    heroTl.fromTo(".gsap-hero-title", 
      { y: 80, autoAlpha: 0 }, // Start state: pushed down and hidden
      { y: 0, autoAlpha: 1, duration: 1.2 } // End state: original position
    )
    .fromTo(".gsap-hero-text",
      { y: 30, autoAlpha: 0 },
      { y: 0, autoAlpha: 1, duration: 1 },
      "-=0.8" // Overlap parameter: start 0.8s before the title finishes
    )
    .fromTo(".gsap-hero-btn",
      { scale: 0.9, autoAlpha: 0 },
      { scale: 1, autoAlpha: 1, duration: 0.8 },
      "-=0.6" // Overlap parameter
    );

  }); // End Context
});

Result: When the page loads, the title rises from the bottom, followed swiftly by the text and button overlapping in a buttery-smooth 60fps sequence.

Step 4: Advanced Execution with ScrollTrigger

A true step-by-step guide to writing GSAP code in Bricks Builder must cover scroll interactions. ScrollTrigger is what turns static pages into immersive journeys.

Let’s say we have an image further down the page (.gsap-parallax-img), and we want it to reveal itself only when the user scrolls it into view.

Add this logic inside your gsap.context() block:

// Scroll-Linked Image Reveal
    gsap.fromTo(".gsap-parallax-img",
      { 
        clipPath: "inset(100% 0% 0% 0%)", // Fully masked from the bottom
        scale: 1.3 // Zoomed in
      },
      {
        clipPath: "inset(0% 0% 0% 0%)", // Fully revealed
        scale: 1, // Normal size
        duration: 1.5,
        ease: "power3.inOut",
        scrollTrigger: {
          trigger: ".gsap-parallax-img",
          start: "top 80%", // Fire when the top of the image hits 80% down the screen
          toggleActions: "play none none reverse" // Reverse animation if user scrolls back up
        }
      }
    );

Real-World Masterclasses: Elite Sites Built on Clean Code

To understand why we bypass default page builder settings for raw code, look at industry benchmarks:

  1. Apple (Product Pages): Apple defines the standard for cinematic scrollytelling. They do not use generic CSS fade-ins. They rely on deep JavaScript math synced to the scrollbar, using scale and spatial clipping (clip-path) to create a 3D illusion on a flat screen.

  2. Locomotive (Design Studio): Known for pioneering smooth scroll web design, Locomotive relies entirely on custom DOM targeting. By separating their HTML architecture from their motion logic, they ensure perfect frame rates.

  3. Stripe: Look closely at Stripe’s animated landing pages. The timing of their UI elements entering the screen is mathematically perfect. They use master timelines (like the one we built in Step 3) to guarantee elements overlap seamlessly.

Comparative Table: Native Bricks Animations vs. Custom GSAP Code

Metric / Capability Native Bricks CSS Entrance Animations Custom GSAP Architecture UX & Agency Impact
Motion Physics 🟡 Basic CSS Transitions (Linear/Ease) 🟢 Advanced Math (Elastic, Inertia, Power4) Premium Vibe: Transforms a template into a bespoke app experience.
Sequencing 🔴 Disconnected (Relies on manual delays) 🟢 Orchestrated (Master Timelines & Overlaps) Cinematic Flow: Guides the user’s eye purposefully.
Scroll Interaction 🟡 Fires once when in view 🟢 Bi-directional, scrubbable, and pinnable Immersive UX: High engagement and lower bounce rates.
DOM Requirements 🟢 Works on anything 🟢 Demands clean HTML (Bricks provides this perfectly) Performance: Guarantees peak Core Web Vitals.

 

FAQ: Troubleshooting Web Animation in WordPress

Q1: How do I prevent the FOUC (Flash of Unstyled Content) before my animation starts? A: Because GSAP executes via JavaScript after the HTML renders, elements may briefly appear on screen before GSAP grabs them and hides them. To fix this, open your Bricks Builder Global CSS and add .gsap-hero-title, .gsap-hero-text, .gsap-hero-btn { visibility: hidden; }. GSAP’s autoAlpha property will instantly turn them visible the millisecond the math begins.

Q2: How do I make my GSAP code responsive so heavy animations don’t run on mobile phones? A: You must use gsap.matchMedia(). Wrap your complex timelines inside an mm.add("(min-width: 992px)", () => { ... }) block. For mobile screens under 991px, you can write simpler, battery-friendly fade-ups. GSAP will automatically destroy the desktop timeline and initialize the mobile one when the user resizes their screen.

Q3: Where exactly do I paste my custom JavaScript if I don’t want to use a child theme? A: While a child theme functions.php file is the agency standard, you can also paste the raw JavaScript directly into Bricks Builder. Go to Bricks -> Settings -> Custom Code, and paste your script (wrapped in <script></script> tags) into the Body (footer) scripts area. Make sure GSAP is enqueued first!

Conclusion & The Architect’s Next Steps

Mastering this step-by-step guide to writing GSAP code in Bricks Builder is the tipping point in your career as a frontend architect.

You are no longer limited by the constraints of visual toggle menus. By combining the bare-metal semantic HTML of Bricks Builder with the boundless physics engine of GSAP, you take absolute control over the browser. You stop building static WordPress pages and start engineering fluid, unforgettable web animation experiences.

Your next practical step: Open your local development environment. Create a Hero section in Bricks, assign your BEM classes, enqueue the GSAP core, and run the Master Timeline script from Step 3. Once you see the perfect power4.out deceleration execute natively on your screen, you will never go back to standard CSS transitions again.