css实现拖动分界线照片前后效果对比代码

代码语言:html

所属分类:其他

代码描述:css实现拖动分界线照片前后效果对比代码

代码标签: css 拖动 分界线 照片 前后 效果 对比

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


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

<head>

  <meta charset="UTF-8">
  

  
  
  
<style>
*,
*::after,
*::before {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

img {
  display: block;
  max-width: 100%;
}

main {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.container {
  display: grid;
  place-content: center;
  position: relative;
  overflow: hidden;
  border-radius: 1rem;
  --position: 50%;
}

.image-container {
  max-width: 800px;
  max-height: 40vh;
  aspect-ratio: 1/1;
}

.slider-image {
  width: 100%;
  height: 80%;
  object-fit: cover;
  object-position: left;
}

.image-before {
  position: absolute;
  inset: 0;
  width: var(--position);
  filter: grayscale(100%)
}

.slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  opacity: 0;
  /* for Firefox */
  width: 100%;
  height: 80%;
}

.slider:focus-visible ~ .slider-button {
  outline: 5px solid black;
  outline-offset: 3px;
}

.slider-line {
  position: absolute;
  inset: 0;
  width: .2rem;
  height: 80%;
  background-color: #fff;
  /* z-index: 10; */
  left: var(--position);
  transform: translateX(-50%);
  pointer-events: none;
}

.slider-button {
  position: absolute;
  background-color: #fff;
  color: black;
  padding: .5rem;
  border-radius: 100vw;
  display: grid;
  place-items: center;
  top: 50%;
  left: var(--position);
  transform: translate(-50%, -50%);
  pointer-events: none;
  /* z-index: 100; */
  box-shadow: 1px 1px 1px hsl(0, 50%, 2%, .5);
}
</style>



</head>

<body>
  <main>
      <div class="container">
        <div class="image-container">
          <img
            class="image-before slider-image"
           src="//repo.bfw.wiki/bfwrepo/image/60078abad6d5a.png"
            alt="color photo"
          />
          <img
            class="image-after slider-image"
            src="//repo.bfw.wiki/bfwrepo/image/60078a8d5f89d.png"
            alt="black and white"
          />
        </div>


        <!-- step="10" -->
        <input
          type="range"
          min="0"
          max="100"
          value="50"
          aria-label="Percentage of before photo shown"
          class="slider"
        />
        <div class="slider-line" aria-hidden="true"></div>
        <div class="slider-button" aria-hidden=&q.........完整代码请登录后点击上方下载按钮下载查看

网友评论0