Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="GSAP">GSAP</div><br>
<div id="WebAnimations1">Web Animations 1</div><br>
<div id="WebAnimations2">Web Animations 2</div>
              
            
!

CSS

              
                body {
  font-size:50px;
  color:white;
  background-color:black;
}
div {
  display:inline-block;
}
              
            
!

JS

              
                TweenMax.defaultEase = Linear.easeNone;
TweenMax.to("#GSAP", 5, {x:200});
TweenMax.to("#GSAP", 1, {rotation:180});
TweenMax.to("#GSAP", 3, {rotation:0, delay:2});

/*
With the Web Animations it's virtually impossible to control various transform components independently with precision (like rotation, scale, skew, position) because if composite is set to "add" the result is still mashed together - rotation affects everything. Actually, it depends on the order in which the animations get created, so this:
*/
var wa1 = document.getElementById("WebAnimations1");
wa1.animate({transform: 'translateX(200px)'}, {duration:5000, fill:"forwards"});
wa1.animate({transform: 'rotate(180deg)', composite:'add'}, {duration:1000, fill:"forwards"});
wa1.animate({transform: 'rotate(-180deg)', composite:'add'}, {delay:2000, duration:3000, fill:"forwards"});

//Results in a COMPLETELY different animation, just by swapping the order of the first two lines:

var wa2 = document.getElementById("WebAnimations2");
wa2.animate({transform: 'rotate(180deg)'}, {duration:1000, fill:"forwards"});
wa2.animate({transform: 'translateX(200px)', composite:'add'}, {duration:5000, fill:"forwards"});
wa2.animate({transform: 'rotate(-180deg)', composite:'add'}, {delay:2000, duration:3000, fill:"forwards"});

/*
But as a user, I just want to make sure that my object moves 200px to the right and ends up rotated upside down. I may not know (and I shouldn't have to care) which other animations were previously set up on the element. Imagine a rollover that must make the object go to a rotation of 0, but it may be halfway through a different one (partially rotated) and I may also have translation or scale or skew animations going on concurrently which I don't want to affect. In order to not interfere with the other animations, I MUST set composite:'add' but if I do that, I must have some way of discerning what the current rotation is and do the math myself to animate it in the opposite direction the same amount just to get to 0. Instead of being able to say rotate(0deg), if the object happens to currently be at rotate(32.574deg), I must do rotate(-32.574deg) to get it back to 0! With GSAP, you don't have to worry about any of that - you just tween the values to whatever you want and they go there. They don't cross-contaminate. You can, of course, do relative animations if you want (which are kinda like composite:'add') by adding "+=" or "-=" prefixes to the values, like rotation:"-=45".
*/

//note: if you'd rather use a GSAP timeline so that you can control the entire animation as a whole, do this instead...
//var tl = new TimelineLite().to("#GSAP", 5, {x:200}).to("#GSAP", 1, {rotation:180}, 0).to("#GSAP", 3, {rotation:0}, 2);
              
            
!
999px

Console