Topics Covered in This JavaScript Tutorial:
Linking to the Google Hosted Version of GreenSock, Creating a Timeline & Animating Multiple Scenes, X & Y Versus XPercent & YPercent, Timeline Labels & Using Seeking to Jump to a Specific Part of a Timeline
Exercise Preview

Exercise Overview
In this comprehensive exercise, you'll master the art of creating professional animated HTML5 banner ads for Google Ads using the industry-standard GreenSock Animation Platform (GSAP). This project combines multiple advanced animation techniques that you'll use regularly in professional web development. We'll emphasize proven workflows and coding best practices that scale from simple banners to complex interactive experiences, ensuring you build maintainable, performant animations that meet today's digital advertising standards.
Animation Development Workflow
Structure Planning
Layout all panels vertically like a storyboard before creating any animations
Timeline Creation
Build a master timeline to control the sequence and timing of all animations
Panel Animation
Animate each panel individually with proper positioning and transitions
Optimization
Add labels for testing and implement overflow hiding for clean presentation
Previewing the Finished Animation
- On your Desktop (the Finder on Mac or Windows Explorer on Windows), navigate to the Class Files folder, then JavaScript Class.
- Open the Done folder, then enter the GSAP-Ad-Banner directory.
CTRL–click (Mac) or Right–click (Windows) on index.html, select Open with and choose your preferred browser.
Study the animation carefully through multiple cycles to understand the timing, pacing, and element interactions. Professional banner ads rely on precise choreography to capture attention without overwhelming viewers. This animation demonstrates a three-panel narrative structure—a proven approach in digital advertising that builds engagement through progressive revelation:

Notice how each panel serves a specific purpose: the opening creates intrigue, the middle panel provides visual appeal and context, and the final panel delivers the call-to-action. This three-act structure mirrors effective storytelling principles and is commonly used by creative teams when designing animated advertisements. Understanding this framework will help you collaborate effectively with designers and create more compelling user experiences.
Linking to the Google Hosted Version of GreenSock
- Launch your code editor and prepare your development environment.
- For this exercise, we'll work with the GSAP-Ad-Banner folder located in Desktop > Class Files > JavaScript Class. Open this folder in your code editor if it supports project-based workflows (such as Visual Studio Code, Sublime Text, or WebStorm).
- In your code editor, open index.html from the GSAP-Ad-Banner folder.
Before examining the page structure, let's address a crucial consideration for Google Ads development: asset optimization and CDN usage.
Google Ads enforces strict file size limitations—currently 150KB total for all assets including HTML, CSS, images, and custom JavaScript. This constraint makes every byte count in professional ad development. Fortunately, Google provides a hosted version of GSAP that doesn't count against your file size quota, making it the optimal choice for banner ad development. This CDN approach also ensures faster loading times and leverages Google's global infrastructure for optimal performance.
Scroll to the bottom of the HTML file and locate the script tag that links to the Google-hosted GSAP library.
This CDN link is maintained at Google's official GSAP resource page: tinyurl.com/gads-gs. Always use the most current version provided by Google to ensure compatibility and access to the latest performance optimizations.
With our animation library configured, let's examine the underlying HTML structure that will serve as the foundation for our multi-panel animation sequence.
Google Ads have a file size limit of 150KB for all assets. Using Google's hosted GSAP library doesn't count toward this limit, making it essential for banner ads.
Google Hosted GSAP
Examining the DOM Structure
Preview index.html in a browser to see the current static layout.
The initial setup displays all three panels in a vertical storyboard arrangement—a strategic approach for complex animation development. This methodology allows you to visualize the complete narrative flow, verify content positioning, and identify potential layout issues before implementing any motion graphics. Professional animation workflows always begin with solid static layouts, as attempting to animate poorly structured HTML often leads to positioning conflicts and maintenance difficulties.
Return to your code editor and examine the HTML structure, paying particular attention to the semantic organization and naming conventions:
<div id="panel1" class="panel"> <h1 id="panel1-text">hungry?</h1> </div> <div id="panel2" class="panel"> <h2 id="panel2-text">How about now?</h2> </div> <div id="panel3" class="panel"> <div id="info">This structure demonstrates professional naming conventions: each of the three panel divs maintains a unique, sequential ID while sharing a common class for shared styling. The consistent naming pattern (panel1, panel2, panel3) makes the code self-documenting and easier to maintain. Each panel measures exactly 300px by 250px—dimensions that comply with Google Ads' standard banner specifications.
Now let's establish our animation strategy. The most efficient approach involves repositioning #panel2 and #panel3 to overlay #panel1 precisely, creating a seamless layered stack.
We'll orchestrate the reveals using GSAP's timeline functionality, with each panel appearing at calculated intervals. Since all panels share identical dimensions, the transitions will appear seamless to viewers. This layering technique is fundamental to creating smooth, professional banner animations that maintain visual consistency throughout the sequence.
With our structural foundation understood, we can begin implementing the timeline-based animation system that will bring this static layout to life.
Creating the Timeline & Animating the First Panel
In the script tag at the bottom of the file, initialize a new GSAP timeline by adding the following code:
<script> let tl = gsap.timeline(); </script>GSAP timelines provide superior control over complex animation sequences compared to individual tweens, allowing precise timing coordination and easier maintenance.
Now we'll create the opening animation that sets the stage for our banner's narrative. Add this engaging entrance effect:
<script> let tl = gsap.timeline(); tl.from('#panel1-text', {duration:0.5, scale:0.5, opacity:0, ease:'back.out'}) </script>This animation uses GSAP's "back.out" easing function, which creates a subtle bounce effect that draws attention without being overly aggressive—perfect for professional advertising contexts.
Save your file and reload the page in the browser to test the animation.
The word hungry? should scale up smoothly with the characteristic back-ease bounce.
If the animation fails to execute despite correct code, disable any ad blockers in your browser. Many ad blockers interfere with GSAP's Google CDN, preventing the library from loading properly.
Excellent! The opening panel demonstrates the kind of polished, attention-grabbing entrance that makes banner ads effective. Now we'll build upon this foundation with the second panel's more complex reveal sequence.
With our opening sequence established, let's escalate the visual impact by introducing the second panel's multi-element animation.
If your GSAP animations aren't working, disable ad blockers in your browser. They can block the GSAP library from Google's servers.
Animating the Second Panel
The second panel combines visual and textual elements strategically: a compelling burger background image paired with bold overlay text reading How about now? This panel demonstrates how effective banner ads layer visual appetite appeal with direct, conversational copy that builds on the initial question.
Position #panel2 to overlay #panel1 precisely by setting its top position to 0. This leverages the absolute positioning already defined in our CSS:
.from('#panel1-text', {duration:0.5, scale:0.5, opacity:0, ease:'back.out'}) .set('#panel2', {top:0})Save and reload the page to observe the current behavior.
You'll notice #panel2 immediately covers #panel1 as soon as the opening text completes its entrance. While functionally correct, this rapid transition doesn't give viewers adequate time to process the opening message—a critical consideration in advertising effectiveness.
Improve the pacing by adding a strategic pause that respects your audience's reading speed:
.set('#panel2', {top:0}, '+=2')This position parameter creates a 2-second reading window, following industry best practices for text-based advertising content. Research shows that viewers need 1.5-2.5 seconds to comfortably process short advertising messages.
Save and reload the page to test the improved timing.
The pacing feels much more natural, but the abrupt panel switch lacks the visual sophistication expected in professional advertising. Let's add a dynamic transition that maintains viewer engagement.
Create a compelling entrance effect for #panel2 that adds visual energy to the transition:
.set('#panel2', {top:0}, '+=2') .from('#panel2', {duration:0.2, opacity:0, scale:1.5})This scale-down effect creates the impression that the burger image is "zooming into focus," a popular technique in food advertising that creates immediate visual impact.
Save and reload the page to evaluate the transition.
The dynamic scaling transition significantly elevates the professional quality of the banner. This type of bold, confident motion is essential for cutting through the visual noise of digital advertising environments.
Complete the second panel sequence by animating the text overlay with a slide-up reveal:
.from('#panel2', {duration:0.2, opacity:0, scale:1.5}) .from('#panel2-text', {duration:0.2, yPercent:100}, '+=0.5')
X & Y Versus XPercent & YPercent
Understanding the distinction between pixel-based and percentage-based positioning is crucial for responsive animation development. While x and y properties move elements by fixed pixel amounts, xPercent and yPercent use the element's own dimensions as the basis for movement calculations.
In this case, yPercent: 100 positions the text element one full height below its normal position, creating a perfect "slide up from below" effect regardless of the text's actual height. This approach ensures your animations remain robust across different content lengths and responsive design scenarios.
For comprehensive guidance on percentage-based animations, consult the official documentation at greensock.com/mistakes#percents
Save and reload the page to see the text slide animation in action.
The smooth upward slide creates anticipation and reveals the text with purpose. This type of directional animation guides the viewer's eye and creates a sense of progression through the advertising narrative.
Complete the second panel's lifecycle by animating the text's exit after an appropriate viewing duration:
.from('#panel2-text', {duration:0.2, yPercent:100}, '+=0.5')
.to('#panel2-text', {duration:0.2, yPercent:100}, '+=2')
This symmetrical exit—sliding back down to the same position it entered from—creates visual continuity and prepares the stage for the final panel's entrance.
Save and reload the page to observe the complete second panel sequence.
The second panel now demonstrates professional animation choreography: dynamic entrance, content reveal, adequate viewing time, and clean exit. Note that any slight visual overflow during the scaling transition will be addressed in our final optimization step.
With two panels successfully animated, we'll now implement the crucial third panel that delivers the call-to-action and completes our advertising narrative.
GSAP Position Properties
| Feature | X & Y Properties | XPercent & YPercent |
|---|---|---|
| Units | Fixed pixels | Percentage of element size |
| Responsiveness | Static positioning | Adaptive to element dimensions |
| Use Case | Precise pixel control | Relative positioning and responsive design |
| Calculation | Manual pixel calculation | Automatic based on element size |
Animating the Third Panel
The final panel serves as the conversion-focused conclusion of our advertising sequence. It features a prominent red information panel containing key messaging (displayed as list items) and a compelling #order-now call-to-action button. This panel's animation must balance urgency with professionalism, encouraging immediate action while maintaining the sophisticated tone established by the previous panels.
Position #panel3 to overlay the previous panels, maintaining our layered reveal strategy:
.to('#panel2-text', {duration:0.2, yPercent:100}, '+=2') .set('#panel3', {top:0})Save and reload the page to observe the current transition behavior.
The third panel appears at the correct moment but lacks the smooth sophistication we've established. To expedite development and testing of the remaining animations, we'll implement a timeline label system that allows us to jump directly to this section during development.
Add a timeline label to create a development checkpoint at the third panel's entrance:
.set('#panel3', {top:0}, 'final')Timeline labels are invaluable for complex animation development, allowing you to test specific sections without waiting through the entire sequence repeatedly.
Create separation between the timeline definition and our development seek command, then implement the jump functionality:
.set('#panel3', {top:0}, 'final') tl.seek('final'); </script>This temporarily bypasses the first two panels, allowing us to focus exclusively on perfecting the final sequence.
Save and reload the page to confirm the seek functionality is working.
The page should now display only the static third panel, with no animation occurring. This confirms we've successfully jumped to the final timeline position.
Implement the information panel's entrance with a smooth upward slide that reveals the content dynamically:
.set('#panel3', {top:0}, 'final') .from('#info', {duration:0.5, yPercent:100}) tl.seek('final');Save and reload the page to test the panel slide animation.
- The red information panel should slide smoothly upward from below the banner area.
- Notice that the #info panel currently obscures the most visually appealing portion of the burger image. We'll address this by repositioning the background image to maintain visual appeal while accommodating the overlay content.
Advanced Animation Techniques
Stagger Animations
Create dynamic list animations where items appear in sequence with controlled delays between each element.
Simultaneous Animations
Use position parameters like '<' to make multiple elements animate at the same time for coordinated effects.
Timeline Label Management
GSAP's label system provides intelligent label management that streamlines complex animation development. When you specify a label as a position parameter, GSAP automatically determines the appropriate action based on the label's current state.
If the label doesn't exist, GSAP creates it at the current timeline position (typically the start of the current tween). If the label already exists, the new tween is positioned at that existing label's timestamp. This behavior enables flexible timeline construction and easy reorganization of animation sequences.
Enhance the visual composition by repositioning the burger image to complement the information panel overlay:
.from('#info', {duration:0.5, yPercent:100})
.to('#panel2', {duration:0.5, y:-65})
tl.seek('final');Save and reload the page to evaluate the improved composition.
The burger repositioning creates better visual balance, but the sequential animation feels disconnected. Professional banner ads require seamless coordination between multiple elements to maintain viewer engagement and create polished visual experiences.
Synchronize the burger repositioning with the information panel's entrance using GSAP's relative positioning syntax:
.to('#panel2', {duration:0.5, y:-65}, '<')
The '<' parameter instructs GSAP to start this tween simultaneously with the previous tween's start time, creating perfectly synchronized motion.
Save and reload the page to observe the coordinated animation.
Excellent! The simultaneous movement creates a cohesive transition that feels intentional and professional. Now we'll add the staggered text reveals that build engagement through progressive disclosure.
Implement a sophisticated staggered animation for the list items that creates visual hierarchy and reading flow:
.to('#panel2', {duration:0.5, y:-65}, '<')
.from('#info li', {duration:0.3, opacity:0, x:50, stagger:0.1}, '+=0.2')
tl.seek('final');Let's analyze the parameters that create this polished stagger effect:
- Each #info li element animates for 0.3 seconds, providing smooth but efficient transitions.
- Elements fade in from opacity: 0 and slide from x: 50, creating a right-to-left entrance that guides reading flow.
- The stagger: 0.1 creates 0.1-second intervals between each element's start time, preventing visual chaos while maintaining dynamic energy.
- The '+=0.2' position parameter adds a brief pause after the panel entrance, allowing viewers to register the new context before text appears.
Save and reload the page to observe the staggered text animation.
The sequential text reveals create professional visual hierarchy and ensure readability—crucial factors in effective call-to-action design.
Complete the sequence with a compelling call-to-action button animation that demands attention without being aggressive:
.from('#info li', {duration:0.3, opacity:0, x:50, stagger:0.1}, '+=0.2')
.from('#order-now', {duration:0.5, scale:0, opacity:0, ease:'back.out'})
The "back.out" easing on the button creates a subtle bounce that suggests interactivity—a psychological trigger that increases click-through rates in digital advertising.
Save and reload the page to see the complete third panel sequence.
Perfect! The final panel demonstrates professional conversion-focused design principles through its carefully orchestrated reveal sequence.
Now let's experience the complete banner animation from beginning to end by removing our development shortcut:
tl.seek('final');Save and reload the page to watch the complete animation sequence.
Observe how the three-panel narrative creates engagement, builds desire, and culminates in a clear call-to-action. This structure exemplifies effective digital advertising storytelling that respects user attention while achieving business objectives.
Our animation sequence is functionally complete, but professional banner development requires attention to visual refinement details that enhance the overall user experience.
Hiding Overflow
During the second panel's scaling animation, the burger image intentionally extends beyond the banner boundaries to create visual impact. However, this "bleed" effect should remain invisible to maintain clean, professional presentation standards expected in digital advertising.
In your code editor, navigate to the css folder and open main.css to access the banner styling rules.
Locate the #banner rule and update the overflow property to contain the scaling animation within the banner boundaries:
#banner { overflow: hidden;Code Omitted To Save Space
}This CSS adjustment ensures that all animation effects remain contained within the banner's defined dimensions, preventing visual artifacts that could detract from the professional presentation.
Save your CSS file and reload the page in the browser.
The animation now maintains perfect visual boundaries while preserving all the dynamic scaling effects that make the banner engaging. This attention to detail separates professional-grade banner ads from amateur implementations.
With our core animation polished, let's implement an optional enhancement that increases advertisement effectiveness through strategic repetition.
Optional Enhancement: Implementing Animation Looping
Banner ad effectiveness often depends on repeated exposure, as viewers may not notice or fully process the message on the first viewing. Strategic looping with appropriate delays respects user attention while maximizing message retention and potential conversion opportunities.
Enhance the timeline initialization with professional looping parameters that balance persistence with user experience:
let tl = gsap.timeline( {repeat:3, repeatDelay:2} );This configuration creates four total animation cycles (the initial play plus three repeats) with a 2-second pause on the call-to-action panel. This timing allows viewers to read and potentially interact with the final message before the sequence restarts.
Save the file and preview in your browser to observe the looping behavior.
The animation now cycles professionally, creating multiple engagement opportunities without becoming intrusive. The strategic pause on the final panel respects user decision-making time while maintaining message visibility—a balance crucial for effective digital advertising performance.
Congratulations! You've successfully created a professional-grade animated banner ad that demonstrates industry best practices in timing, visual hierarchy, narrative structure, and technical implementation. This project showcases the kind of polished, engaging content that drives results in today's competitive digital advertising landscape.