css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="app h-screen bg-grey-light font-sans overflow-auto px-2 py-8">
  
  <div class="text-black text-center mb-8">
    <div class="block text-5xl mb-4">🌗</div>
    <h1 class="text-xl ">Responsive <br class="sm:hidden">Image & Content Comparison</h1>
  </div>
  
  <div class="example my-8 p-4 max-w-lg mx-auto bg-white shadow border w-full rounded">
    <h3 class="text-xl mb-4 text-grey-darkest">Compare Elements</h3>
    
    <comparify class="bg-white h-64 w-full">
      <template slot="first">
        
        <div class="sm-size border-t bg-indigo font-sans antialiased h-full">
         
          <div class="header h-16 flex items-center px-4 bg-white shadow-md">
          <div class="navbar-item flex items-center w-8">
            <svg class="logo h-16 w-8 text-indigo-darker" xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-reactid="1351"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>
          </div>
          <div class="logo-type ml-2 text-indigo-darker tracking-wide font-bold">APP</div>

          <div class="search hidden sm:block ml-4">
            <input type="text" class="border-2 px-4 py-2 rounded border-grey-lighter bg-grey-lighter hover:border-grey" placeholder="Search...">
          </div>

          <span class="ml-auto"></span>

          <div class="navbar-item flex items-center">

            <a href="#" class="no-underline px-4 py-2 rounded bg-indigo-dark hover:bg-indigo-light text-white">Login</a>
            <!--<a href="#" class="btn px-4 py-1 no-underline">Register</a>-->
          </div>
        </div>
          <div class="emoj flex items-center justify-center text-5xl mt-24">
            😊
          </div>
        </div>
        
      </template>
      <template slot="second">
         
        <div class="sm-size border-t bg-grey font-sans antialiased h-full">
         
          <div class="header h-16 flex items-center px-4 bg-grey-darkest shadow-md">
          <div class="navbar-item flex items-center w-8">
            <svg class="logo h-16 w-8 text-white opacity-75" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-reactid="1351"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>
          </div>
          <div class="logo-type ml-2 text-white tracking-wide font-bold">APP</div>

          <div class="search hidden sm:block ml-4">
            <input type="text" class="border-2 px-4 py-2 rounded border-grey-lighter bg-grey-lighter hover:border-grey" placeholder="Search...">
          </div>

          <span class="ml-auto"></span>

          <div class="navbar-item flex items-center">

            <a href="#" class="no-underline px-4 py-2 rounded bg-grey-dark hover:bg-grey-light text-black">Login</a>
            <!--<a href="#" class="btn px-4 py-1 no-underline">Register</a>-->
          </div>
        </div>
          <div class="emoj flex flex-col items-center justify-center mt-24">
            <div class="text-5xl">😎</div>
            html elements
          </div>
          
        </div>
        
      </template>
    </comparify>    
  </div>
  
  <div class="example my-8 p-4 max-w-lg mx-auto bg-white shadow border rounded" style="max-height:350px">
    
    <h3 class="text-xl mb-4 text-grey-darkest">Compare Images</h3>
    
    <comparify class="bg-white h-64 w-full" value="45">
        
        <img slot="first" class="h-64 object-fit-cover h-full w-full" src="https://images.unsplash.com/photo-1525936607120-6a787fb05d6a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=3cb09a29812d04718a5855dc61442612&auto=format&fit=crop&w=800&q=90" alt="">
        <img slot="second" class="object-fit-cover h-full w-full" src="https://images.unsplash.com/photo-1510149053388-87292573d661?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=18d7ef1ac6ffcd0a644aaa1d330278c6&auto=format&fit=crop&w=800&q=90" alt="">
        
    </comparify>    
  </div>
  
  <div class="text-center text-5xl text-black">~</div>
  
  <div class="usage my-8 p-4 max-w-md mx-auto bg-white shadow border w-full rounded">
    
    <h3 class="text-xl mb-4 text-grey-darkest">Usage</h3>
    <div>
      
      <pre class="bg-grey-light p-4 rounded">
<code><b>&ltcomparify></b>
  &lttemplate <b>slot="first"></b>
    First content here.
  &lt/template>
  &lttemplate <b>slot="second"></b>
    Second content here.
  &lt/template>
<b>&lt/comparify></b></code></pre>
      
      <div class="mt-4">
        <p>Props: value, step</p>
      </div>
    </div>
    
  </div>
  
  
  
  <footer class="text-center">
    Built with Vue &amp; Tailwindcss by <a href="https://twitter.com/imesutkoca" class="font-bold text-grey-darkest no-underline" target="_blank">Mesut Koca</a>
  </footer>
</div>






<template id="compare-template">
  <div class="compare-wrapper">
    <div class="compare">
      
      <div class="compare__content" :style="{'width': width}">
        <slot name="first"></slot>
      </div>
        
      <resize-observer @notify="handleResize"></resize-observer>
      <div class="handle-wrap" :style="{left:`calc(${compareWidth + '%'} - var(--handle-line-width) / 2`}">
        <div class="handle">
          <svg class="handle__arrow handle__arrow--l" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-left"><polyline points="15 18 9 12 15 6"/></svg>
          <svg class="handle__arrow handle__arrow--r" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"/></svg>

        </div>
        <span class="handle-line"></span>
      </div>
      

      <div class="compare-overlay " :style="{width:`calc(${compareWidth + '%'})`}">

        <div class="compare-overlay__content" :style="{ 'width': width}">
          <slot name="second"></slot>
        </div>
      </div>
    
      
        
    </div>
  <input type="range" min="0" max="100" :step="step" class="compare__range" :value="compareWidth" @input="handleInput" tabindex="-1">
    
  </div>
</template>
            
          
!
            
              :root{
  --handle-bg: blue;
  --handle-width: 30px;
  --handle-height: 30px;
  --handle-chevron-size: 20px;
  
  --handle-line-bg: blue;
  --handle-line-width: 2px;
  --handle-line-height: 100%;
  
  --z-index-handle: 5;
  --z-index-handle-line: 4;
  --z-index-range-input: 6;
}

.compare-wrapper{
  position: relative;
}
.compare,
.compare__content{
  position: relative;
  height: 100%;
}

.compare-overlay{
  position: absolute;
  overflow:hidden;
  height: 100%;
  top:0;
}
.compare-overlay__content{
  position:relative;
  height: 100%;
  width: 100%;
}

.handle__arrow{
  position: absolute;
  width: var(--handle-chevron-size);
}
.handle__arrow--l{
  left:0;
}
.handle__arrow--r{
  right:0;
}

.handle-wrap{
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 50%;
  height: 100%;
  transform: translate(-50%, -50%);
  z-index: var(--z-index-handle);
}
.handle{
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  background: var(--handle-bg);
  border-radius: 50%;
  width: var(--handle-width);
  height: var(--handle-height);
}

.handle-line{
  content: '';
  position: absolute;
  top:0;
  width: var(--handle-line-width);
  height: 100%;
  background: var(--handle-line-bg);
  z-index: var(--z-index-handle-line);
  pointer-events:none;
  user-select:none;
}

.compare__range{
  position: absolute;
  cursor: ew-resize;
  left: calc(var(--handle-width) / -2);
  width: calc(100% + var(--handle-width));
  transform: translatey(-50%);
  top: calc(50%);
  z-index: var(--z-index-range-input);
  -webkit-appearance: none;
  height: var(--handle-height);
  /* debugging purposes only */
  background: rgba(0,0,0,.4);
  opacity: .0;
}

.object-fit-cover{
  object-fit: cover;
}
            
          
!
            
              Vue.component('comparify', {
  props:{
    value: { default: 50 },
    step: { default: '.1' }
  },
  template:`#compare-template`,
  data(){
    return {
      width: null,
      compareWidth: this.value,
    }
  },
  watch:{
    value(){
      this.compareWidth= this.value
    }
  },
  mounted(){
    this.width = this.getContainerWidth();
  },
  methods:{
    handleInput(e){
      this.compareWidth = e.target.value
      this.$emit('input', e.target.value)
    },
    handleResize(){
      const w = this.getContainerWidth();
      if(w === this.width)
        return;
      this.width = w
      console.log(this.width)
    },
    getContainerWidth(){
      return window.getComputedStyle(this.$el,null).getPropertyValue('width')
    },
  }
})

new Vue({
  el:'.app'
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console