Pen Settings



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


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


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.


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.


                <link href='//,400' rel='stylesheet' type='text/css'>
<h1>GSAP FLIP Demo</h1>
<div id="flex">
  <div id="container1">
  <div id="container2"></div>


                body {
  color: white;
  background-color: black;
  padding: 0 20px;
  font-family: 'Signika Negative';
#flex {
  display: flex;
  overflow: hidden;
#container1, #container2 {
  width: 50%;
#container1 div, #container2 div {
  margin-bottom: 3px;
  height: 26px;
  background-color: #777;
  border-radius: 13px;
  border: 1px solid #333;
  text-align: center;


                flip("#container1 div", doMyStuff, {stagger: 0.1, duration: 1.5, ease: "elastic", delay: 1});

Copy this to your project. Pass in the elements (selector text or NodeList or Array), 
then a function/callback that actually performs your DOM changes, and optionally a vars 
object that contains any of the following properties to customize the transition:

 - duration [Number] - duration (in seconds) of each animation
 - stagger [Number | Object | Function] - amount to stagger the starting time of each animation. You may use advanceds staggers too (see
 - ease [Ease] - controls the easing of the animation. Like "power2.inOut", or "elastic", etc.
 - onComplete [Function] - a callback function that should be called when all the animation has completed.
 - delay [Number] - time (in seconds) that should elapse before any of the animations begin. 

This function will return a Timeline containing all the animations. 
function flip(elements, changeFunc, vars) {
  elements = gsap.utils.toArray(elements);
  vars = vars || {};
  let tl = gsap.timeline({onComplete: vars.onComplete, delay: vars.delay || 0}),
      bounds = => {
        let b = element.getBoundingClientRect();
        element._flip && element._flip.progress(1);
        element._flip = tl;
        return b;
      copy = {},
  for (p in vars) {
    p !== "onComplete" && p !== "delay" && (copy[p] = vars[p]);
  copy.x = (i, element) => "+=" + (bounds[i].left - element.getBoundingClientRect().left);
  copy.y = (i, element) => "+=" + (bounds[i].top - element.getBoundingClientRect().top);
  return tl.from(elements, copy);

//this function just takes all the <div> elements from #container1 and puts them into #container2 in a randomized order. 
function doMyStuff() {
  var elements = gsap.utils.toArray("#container1 div"),
      newContainer = document.querySelector("#container2"),
  elements.sort(function() { return 0.5 - Math.random(); });
  for (i = 0; i < elements.length; i++) {