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 class="ImageComparison">
  <div class="overlap">
    <div class="clipper">
      <div class="try yor">
        <div class="text-r text"> Innocent Yor </div>
        <img src='https://static.zerochan.net/Yor.Briar.full.3493455.png'alt="">
      </div>
    </div>
    <div class="try2 yor">
      <div class="text-l text"> Assassin Yor </div>
      <img src='https://images.unsplash.com/photo-1482245294234-b3f2f8d5f1a4?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=1922d6e6f96e8e67aac67057877e15da' alt="">
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  width:100%;
  height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
}
.yor {
  width: 500px;
  height: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  object-fit: cover;
  justify-content: center;
}

img {
  width: 500px;
  height: auto;
}

.text {
  margin-bottom: 12px;
  font-size: 22px;
  pointer-events: none;
}

.try {
  background: yellow;
}

.try2 {
  background: blue;
  position: absolute;
  top: 0;
  left: 0;
  .text {
    color: white;
  }
}

.overlap {
  position: relative;
  border-radius: 10000px;
  overflow: hidden;
  width: 500px;
  height: 500px
}

.clipper {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  overflow: hidden;
  z-index: 100;
}
              
            
!

JS

              
                const overlap = document.querySelector('.overlap');
const clipper = document.querySelector('.clipper');

// make sure things work when the window gets resized, so we'll use a few variables that get set on resize (and initially)
let offset, clamp;
function setOffset() {
  offset = overlap.getBoundingClientRect().left;
  // a clamping function so the width is limited to between 0 and the width of the overlap.
  clamp = gsap.utils.clamp(0, overlap.getBoundingClientRect().width);
}
setOffset(); // set them initially
window.addEventListener("resize", setOffset); // and on resize

Observer.create({
  target: document,
  type: "pointer,touch", // make it work on touch and pointer/mouse devices
  onMove: self => clipper.style.width = clamp(self.x - offset) + "px",
});
              
            
!
999px

Console