Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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='i'>
  <div id='heart'>❤</div>
  <div id='gsap'>GSAP</div>
</div>

<p>https://www.greensock.com/gsap-js/</p>
              
            
!

CSS

              
                #i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 380px;
  height: 120px;
  margin: -60px 0 0 -190px;
  color: #FFFFFF;
  font-weight: bold;
  font-size: 90px;
  line-height: 120px;
  cursor: pointer;
}

#heart {
  position: absolute;
  font-family: "Trebuchet MS", Webdings;
}

#gsap {
  position: absolute;
  left: 120px;
  width: 260px;
  height: 120px;
  text-align: center;
  letter-spacing: -4px;
  color: #000000;
  background: #91E600;
}

body {
  background: #111111;
  font: normal 13px "Trebuchet MS", Arial, sans-serif;
}

p {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  color: #666;
}
              
            
!

JS

              
                swing('#gsap');

// just so you can repeat the effect easily. It's not configured well for replaying while it's in motion though; wait until the animation stops to get the full effect again.
$('#i').on('click', function() { swing('#gsap') });


function swing(target) {
  // the values in vars can (and should) be tweaked to modify the way the swing works
  // * = affected by power
  var vars = {
    origin: 'top center',   // transformOrigin
    perspective: 600,       // transformPerspective
    ease: Power1.easeInOut, // an easeInOut should really be used here...
    power: 1,               // multiplier for the effect that is reduced to 0 over the duration
    duration: 5,            // total length of the effect (well, it can be up to vars.speed longer than this)
    rotation: -90,          // start rotation, also stores target rotations during tween
    maxrotation: 60,        // * max rotation after starting
    speed: 0.5,             // minimum duration for each swing
    maxspeed: 0.2           // * extra duration to add to the larger swings (any sort of real physics seems like overkill)
  };
  
  // target could be a string selector (it will be selected each swing though...), or a DOM or jQuery object
  vars.target = target;
  
  // starting position
  TweenMax.set(vars.target, { rotationX: vars.rotation, transformOrigin: vars.origin, transformPerspective: vars.perspective });
  
  TweenMax.to(vars, vars.duration, { power: 0, delay: 1, onStart: nextSwing, onStartParams: [vars] });
}


function nextSwing(vars) {
  if (vars.power > 0) {
    vars.rotation = (vars.rotation > 0 ? -1 : 1) * vars.maxrotation * vars.power;
    TweenMax.to(vars.target, vars.speed + vars.maxspeed * vars.power, { rotationX: vars.rotation, ease: vars.ease, onComplete: nextSwing, onCompleteParams: [vars] });
  } else {
    TweenMax.to(vars.target, vars.speed, { rotationX: 0, ease: vars.ease, clearProps: 'all' });
  }
}
              
            
!
999px

Console