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

              
                <main id="image1">
  <div id="outer" class="outer">
    <div class="image"><img src="https://designkojo.com/hide-images/2020-10-21-07.11.03-later-winter.jpg" alt="add an alt" /></div>
    <div class="image image1"><img src="https://designkojo.com/hide-images/2020-10-21-07.11.03-winter-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 id="image" class="image-wrapper">
      <div class="image image-inner"><img src="https://designkojo.com/hide-images/2020-10-21-07.11.03-2.jpg" alt="add an alt" />
      </div>
      <div id="handle"></div>
    </div>
    <div id="switch" class="caption">A winter and summer wonderland <span style="border: 1px solid; padding: 1px; float: right;">Switch Winter Image</span></div>
  </div>
  <div class="mobile-initiation">
    <div class="mobile-initiation-inner">
      <ol>
        <li>Touch theScreen to Initiate Slider</li>
        <li>User Green bar to reveal and hide</li>
      </ol>
    </div>
  </div>
</main>

              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background: #1b2b34;
}

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

.outer {
  max-width: 1010px;
  /*position: absolute;*/
  position: relative;
  /*height: 750px;*/
  width: 100%;
}

#image {

}

.image {
  position: absolute;
  overflow: hidden;
  /*height: 800px;*/
  user-select: none;
  -moz-user-select: none;
  -webkit-user-select:none;
  -webkit-touch-callout:none;
  pointer-events: none;
}

.image1 {
  transition: opacity 1s;
}

.image-inner {
  position: unset;
}

/*.image::-moz-selection,
.image::selection,
.image::-ms-value {
  background-color: transparent;
  color: #000;
  user-select: none;
  -moz-user-select: none;
}*/

.caption {
  position: absolute;
  /*bottom: 0;*
  transform: translateY(100%);*/
  height: 40px;
  width: 100%;
  background-color: #1b2b34;
  color: white;
  line-height: 1.2em;
  padding: 1em;
  font-family: "Cabin", Arial, Geneva, sans-serif;
  font-size: .72em;
  z-index: 101;
  user-select: none;
}

img {
  width: 100%;
  /*object-fit: fill;*/
}

.image-inner img {
  width: calc(100vw);
  max-width: 1010px;
}

/*#image {*/
/*  position: relative;*/
/*}*/

#handle {
  position: absolute;
  right: 0;
  top: 0;
  width: 15px;
  height: 99.01%;
  background: #37b822ad;
  display: none;
  text-shadow: 2px 2px 4px;
}
#handle:hover {
  pointer-events: fill;
  cursor: col-resize;
}
.outer:hover #handle {
  display: block;
}
.image-wrapper {
  width: 50%;
  overflow: hidden;
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
}

.outer:hover .image-wrapper {
  box-shadow: 2px 0 black;
}

#night {
  opacity: 0;
  transition: opacity 2s;
  z-index: -10;
}

@media(pointer: coarse) {
  .outer:hover .image-wrapper {
  box-shadow: 10px 0 #1b2b34;
  }
}

@media screen and ( min-width: 567px )  {
  .caption {
    font-size: 1.2em;
    padding: 0.5em;
  }
}

.mobile-initiation {
  display: none;
}

@media screen and ( max-width: 1820px )  {
 .mobile-initiation {
    position: absolute;
    display: flex;
    justify-content: center;
    font-size: 0.8em;
    padding: 0.5em;
    background: rgba(55, 184, 34, 0.0);
    top: 0;
    width: 100%;
    height: 100vh;
    z-index: 101;
  }

  .mobile-initiation-inner {
    position: absolute;
    top: 200px;
    font-size: 1em;
    padding: 0.5em;
    background: rgba(55, 184, 34, 0.90);
    width: 240px;
    height: 60px;
    z-index: 102;
    border-radius: 2px;
    box-shadow: 1px 1px 1px black;
    color: black;
  }
  .mobile-initiation-inner ol {
    list-style-position: outside;
    margin-left: -15px;
  }
}
              
            
!

JS

              
                const wrapper1 = document.getElementById("image1");
const wrapper = document.getElementById("image");
const outer = document.getElementById("outer");
const night = document.getElementById("night");
const handle = document.getElementById("handle");
const switchImage = document.getElementById("switch");
const image1 = document.querySelector(".image1");
const mobileInitiation = document.querySelector(".mobile-initiation")

let imageWrapper;
let setWidth = 1010;
var imageOpacity = 100;

switchImage.addEventListener('click', function () {
  if (imageOpacity === 0) {
    image1.style.opacity = 100;
    imageOpacity = 100;
  } else {
    image1.style.opacity = 0;
    imageOpacity = 0;
  }
});

/* Touch  Message */
document.addEventListener("DOMContentLoaded", function() {
  mobileInitiation.addEventListener("click", function () {
    mobileInitiation.style.display = "none";
    handle.style.display ="block";
  });

});

/* Mouse Desktop */
handle.addEventListener('mousedown', function () {

  var width = document.body.clientWidth;

  wrapper1.addEventListener('mousemove', mouseMove);

  handle.onmouseup = function (e) {
    wrapper1.removeEventListener('mousemove', mouseMove);
  };
  window.addEventListener('mouseup', function (event) {
    wrapper1.removeEventListener('mousemove', mouseMove);
  })

  function mouseMove(e) {
    var x = e.clientX;

    var outerTracker = outer.getBoundingClientRect();

    let mousePointerPos;
    mousePointerPos = x - outerTracker.x;

    // For Screens smaller that the max-width
    if (width <= setWidth) {
      // Stop handle from going more than 100% width
      if (mousePointerPos <= outerTracker.width) {
        wrapper.style.width = x + "px";
      } else {
        wrapper.style.width = outerTracker + "px";
      }
    } else {
      imageWrapperPercent = mousePointerPos / 10;
      // Stop handle from going more than 100% width
      if (imageWrapperPercent <= 100) {
        wrapper.style.width = imageWrapperPercent + "%";
      } else {
        wrapper.style.width = "100%";
      }
    }

    // Night
    if (mousePointerPos < 20) {
      night.style.opacity = "100"
      night.style.zIndex = 10;
    }
    if (mousePointerPos > 20) {
      night.style.opacity = "0"
    }
  }
});


/* Touch */
handle.addEventListener('touchstart', function (e) {

  console.log("touchstart");

  //e.preventDefault();

  var width = document.body.clientWidth;

  wrapper1.addEventListener('touchmove', mouseMove); // change from mousemove event

  handle.ontouchend = function (e) {
    handle.style.display ="none";
  }

  function mouseMove(e) {
    //e.preventDefault();
    var xTouch = e.clientX || e.targetTouches[0].pageX;

    var outerTracker = outer.getBoundingClientRect();

    let mousePointerPosX;
    mousePointerPosX = xTouch - outerTracker.x;

    // doesn't work on window resize
    if (width <= setWidth) {
      // Stop handle from going more than 100% width
      if (mousePointerPosX <= outerTracker.width) {
        wrapper.style.width = xTouch + "px";
      } else {
        wrapper.style.width = outerTracker + "px";
      }

    } else {

      imageWrapperPercent = mousePointerPosX / 10;
      // Stop handle from going more than 100% width
      if (imageWrapperPercent <= 100) {
        wrapper.style.width = imageWrapperPercent + "%";
      } else {
        wrapper.style.width = "100%";
      }

    }
    // Night
    if (mousePointerPosX < 50) {
      night.style.opacity = "100"
      night.style.zIndex = 10;
    }
    if (mousePointerPosX > 50) {
      night.style.opacity = "0"
    }
  } // end touch mouseMove()

}, false);
              
            
!
999px

Console