js实现立体前后照片对比拖拽效果代码

代码语言:html

所属分类:拖放

代码描述:js实现立体前后照片对比拖拽效果代码

代码标签: js 立体 前后 照片 对比 拖拽

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
.compare {
  --mask-width: 50%;
  --handle-size: 32px;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.compare__separator {
  position: absolute;
  top: 0;
  height: 100%;
  left: var(--mask-width);
  width: 2px;
  margin-left: -1px;
  background: black;
  z-index: 1;
  pointer-events: none;
}

.compare__image-one {
  width: 100%;
  display: block;
}

.compare__mask {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  z-index: 1;
  background: white;
  overflow: hidden;
  width: var(--mask-width);
}

.compare__image-two {
  height: 100%;
  width: auto;
}

.compare__input {
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  top: 0;
  left: calc(var(--handle-size) / -2);
  width: calc(100% + var(--handle-size));
  height: 100%;
  opacity: 0;
  z-index: 2;
  cursor: col-resize;
  background-color: transparent;
}

/* Firefox */
.compare__input::-moz-range-track {
  height: 100%;
}

.compare__input::-moz-range-thumb {
  height: 100%;
  border-radius: 0;
  width: var(--handle-size);
  border: none;
}

/* Webkit */
.compare__input::-webkit-slider-runnable-track {
  height: 100%;
}

.compare__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 100%;
  border-radius: 0;
  width: var(--handle-size);
  border: none;
}

.compare__icon {
  position: absolute;
  z-index: 2;
  color: #333;
  width: var(--handle-size);
  height: var(--handle-size);
  top: 50%;
  left: var(--mask-width);
  transform: translate(-50%, -50%);
  padding: 6px;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: white;
}

.compare__icon path {
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2px;
}

/* ----- DEMO AND DEBUG ----- */
:root {
  --light-green: #2ecc71;
  --blue: #3498db;
  --red: #e74c3c;
  --blue-rgb: 52 152 219;
}

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  padding: 80px 40.........完整代码请登录后点击上方下载按钮下载查看

网友评论0