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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <main id="wrapper-outer">

    <div id="outer" class="outer">

        <div class="image"><img src="https://designkojo.com/hide-images/2020-10-21-07.11.03-winter-2.jpg" alt="add an alt"/></div>
        <div id="wrapper-percent" class="image"><img src="https://designkojo.com/hide-images/2020-10-21-07.11.03-2.jpg" alt="add an alt"/></div>
      <div id="night" class="image"><img src="https://designkojo.com/hide-images/2020-10-21-07.11.03-night.jpg" alt="add an alt"/></div>

      <div class="image caption">A winter and summer wonderland</div>
    </div>

</main>






              
            
!

CSS

              
                /* reset */
* {
  margin: 0;
  box-sizing: border-box;
}

body {
  box-sizing: border-box;
  margin: 0;
}

main {
  width: 100vw;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.outer {
  width: 1010px;
  position: relative;
  height: 750px;
}

.image {
  position: absolute;
  overflow: hidden;
  height: 800px;
}

.caption {
  position: absolute;
  bottom: 0;
  height: 40px;
  width: 100%;
  background-color: #1b2b34;
  color: white;
  line-height: 1.2em;
  padding: .5em;
  font-family: "Cabin", Arial, Geneva, sans-serif;
  font-size: 1.2em;
}

.image:nth-child(2) {
  width: 50%;
}

.image:nth-child(2) img {
}

#night {
  opacity: 0;
  transition: opacity 2s;
}



              
            
!

JS

              
                const wrapperOuter  =  document.getElementById("wrapper-outer");
const wrapperPercent  =  document.getElementById("wrapper-percent");
const outer = document.getElementById("outer");
const night = document.getElementById("night");

let width = document.body.clientWidth;
let imageWrapperPercent;

wrapperOuter.addEventListener('mousemove', mouseMove );

function mouseMove(e) {
  
  var x = e.clientX;
  console.log(x);
  
  var outerTracker = outer.getBoundingClientRect();
  let mousePointerPos;
  
  mousePointerPos = x - outerTracker.left;
  console.log(mousePointerPos);
  
  //wrapperPercent.style.width = x + "px"; // wrapper width using clientX
  wrapperPercent.style.width = mousePointerPos + "px"; // wrapper width using mouse postion in the box
  
  // convert to a % 
  //imageWrapper =  mousePointerPos/10;
  //wrapperPercent.style.width = imageWrapper + "%";

  // Night Image Show and Hide
  /*if(mousePointerPos < 0) {
    night.style.opacity = "100"
  }
  if(mousePointerPos > 0) {
    night.style.opacity = "0"
  }*/

}


              
            
!
999px

Console