5

Simpel before and after comparing of two images

 2 years ago
source link: https://codepen.io/netsi1964/pen/JjyKJpN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Pen Settings

HTML Preprocessor

Add Class(es) to <html>

Stuff for <head>

0 unsaved changes
xxxxxxxxxx
<div class="images">
<div class="before"></div>
<div class="after"></div>
  </div>
  <div class="copy">© 2021, Jeanne Christensen
</div>
xxxxxxxxxx
* {
  box-sizing: border-box;
}
html, body {
  background: black;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  font-family: sans-serif;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24pt;
}
.images {
  width: 960px;
  height: 720px;
  outline: solid;
  display: block;
  position: relative;
  cursor: col-resize;
xxxxxxxxxx
const after = document.querySelector('.after');
const maxWidth = parseInt(getComputedStyle(after).width)
window.addEventListener('mousemove', (evt) => {
  evt.preventDefault();
  evt.stopPropagation();
  change(evt.offsetX)
});
window.addEventListener('touchmove', (evt) => {
  evt.preventDefault();
  evt.stopPropagation();
  change(evt.touches[0].clientX);
  return false;
});
function change(x) {
console.log(x)
  after.style.width = `${Math.min(maxWidth, x)}px`
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK