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 class="control">
  <input type="checkbox" id="use-expo-scale" checked>
  <label for="use-expo-scale">Use ExpoScaleEase</label>
</div>

<div class="control">
  <input type="checkbox" id="show-overflow">
  <label for="show-overflow">Show Overflow</label>
</div>

<section class="demo">
  
  <div id="outer1" class="outer">
    <div id="inner1" class="inner">
      <img id="image1" class="image" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/kitten-01.jpg?v=8">
      <div class="title">A Kitten</div>
    </div>
  </div>
  
  <div id="outer2" class="outer">
    <div id="inner2" class="inner">
      <img id="image2" class="image" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/kitten-01.jpg?v=8">
      <div class="title">A Kitten</div>
    </div>
  </div> 
  
</section>
              
            
!

CSS

              
                body {
  overflow: hidden;
  padding: 20px;
}

.outer {
  position: absolute;
  top: 20px;
  left: 175px;
  width: 250px;
  height: 250px;
  overflow: hidden;
  background: #f06292;
  transform-origin: 0px 0px;
  will-change: transform, opacity, visibility;
}

.inner {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #4fc3f7;
  transform-origin: 0px 0px;
  will-change: transform;
}

.image {
  position: absolute;
  left: 0;
  top: 0;
  width: 1000px;
  height: 500px;
  transform-origin: 0px 0px;
  will-change: transform, opacity;
}

.title {
  position: relative;
  color: #fff;
  margin: 10px;
  font-size: 24px;
  font-weight: 700;
}

.demo {
  position: relative;
}

.control {
  margin-bottom: 4px;
}

.show-overflow {
  .outer {
    overflow: visible;
  }

  .image {
    opacity: 0.5;
  }
}

#outer1 {
  visibility: hidden;
}

#outer2 {
  visibility: visible;
}

.use-expo-scale {
  #outer1 {
    visibility: visible;
  }

  #outer2 {
    visibility: hidden;
  }
}


              
            
!

JS

              
                console.clear();

var demo = document.querySelector(".demo");
var useExpoScale = document.querySelector("#use-expo-scale");
var showOverflow = document.querySelector("#show-overflow");

var duration = 1;
var baseEase = Power1.easeInOut;

var tl = new TimelineMax({
  paused: true,
  delay: 1,
  repeat: -1,
  repeatDelay: 1,
  yoyo: true
});

window.addEventListener("load", onLoad);

function onLoad() {
    
  tl.add(scaleAnimation("#outer1", true), 0)
    .add(scaleAnimation("#outer2", false), 0)
    .play();
  
  onExpoChange();
  onOverflowChange();
  useExpoScale.addEventListener("change", onExpoChange);
  showOverflow.addEventListener("change", onOverflowChange);
}

function scaleAnimation(selector, useExpo) {
  
  var outer = document.querySelector(selector);
  var inner = outer.querySelector(".inner");
  var image = outer.querySelector(".image");
  
  var bounds = outer.getBoundingClientRect();
  
  var endWidth = image.naturalWidth;
  var endHeight = image.naturalHeight;  
  
  var scaleX = endWidth / bounds.width;
  var scaleY = endHeight / bounds.height;
  
  var invScaleX = 1 / scaleX;
  var invScaleY = 1 / scaleY;
  
  TweenLite.set(image, {
    x: -175,
    scale: 0.5
  });
    
  return new TimelineMax()
    .to(outer, duration, {
      scaleX: scaleX,
      ease: useExpo ? ExpoScaleEase.config(1, scaleX, baseEase) : baseEase,
    }, 0)
    .to(outer, duration, {
      scaleY: scaleY,
      ease: useExpo ? ExpoScaleEase.config(1, scaleY, baseEase) : baseEase,
    }, 0)
    
    .to(inner, duration, {
      scaleX: invScaleX,
      ease: useExpo ? ExpoScaleEase.config(1, invScaleX, baseEase) : baseEase,
    }, 0)
    .to(inner, duration, {
      scaleY: invScaleY,
      ease: useExpo ? ExpoScaleEase.config(1, invScaleY, baseEase) : baseEase,
    }, 0)
    
    // This is being scaled from 0.5 to 1, but I'm using the ease config values used on
    // the outer element to match its speed. Try using ExpoScaleEase.config(0.5, 1, baseEase)
    // to see the difference. It will create a slightly different effect.
    .to(image, duration, {
      x: 0,
      scaleX: 1,
      ease: useExpo ? ExpoScaleEase.config(1, scaleX, baseEase) : baseEase,
    }, 0)
    .to(image, duration, {
      scaleY: 1,
      ease: useExpo ? ExpoScaleEase.config(1, scaleY, baseEase) : baseEase,
    }, 0);
}

function onExpoChange() {
  
  if (useExpoScale.checked) {
    demo.classList.add("use-expo-scale");
  } else {
    demo.classList.remove("use-expo-scale");
  }
}

function onOverflowChange() {
  
  if (showOverflow.checked) {
    demo.classList.add("show-overflow");
  } else {
    demo.classList.remove("show-overflow");
  }
}

              
            
!
999px

Console