CSS-滑块

7 篇文章 0 订阅

原视频:CodingStartup起码课

移动滑块,显示图片的黑白区域

在这里插入图片描述
在这里插入图片描述

<div class="comparison" style="--slide:500">
  <input type="range" class="slider" min="1" max="1000" value="500" oninput="this.parentNode.style.setProperty('--slide',`${this.value}`)">
</div>
body{
  display:flex;
  justify-content:center;
  align-items:center;
  min-height:100vh;
}
.comparison{
  --image:url(https://images.unsplash.com/photo-1629337419504-9611ef2dfa94?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80);
  --height:700px;
  width:900px;
  height:var(--height);
  position:relative;
  
  overflow:hidden;
  box-shadow:0px 2px 6px rgba(0,0,0,0.15);
  border-radius:4px;
}


.comparison::before,
.comparison::after {
  content: '';
  display: block;
  width: inherit;
  height: inherit;
  background-size: cover;
  background-image: var(--image);
  position: absolute;
  top: 0;
  left: 0;
}
/*将before伪类设置为灰度100%的滤镜*/
.comparison::before{
  filter: grayscale(100%);
}
/*将after伪类设置:剪裁可以显示区域*/
.comparison::after{
  clip-path: inset(0 0 0 calc(var(--slide) /10 * 1% ));
}

/*设置滑块样式:不显示滑块*/
.slider{
  position:absolute;
  top:0;
  left:0;
  
  -webkit-appearance:none;
  appearance:none;
  outline:none;
  margin:0;
  
  background:transparent;
  width:100%;
  height:100%;
  z-index:100;
}
/*-webkit-slider-thumb:type为range的input标签内的一种伪类样式,用于设置range的滑块的具体样式,该伪类只在内核为webkit/blink的浏览器中有效*/
/*将滑块的操作部分,改成宽14高100%的黑色长条,鼠标样式改成双向箭头*/
.slider::-webkit-slider-thumb{
  -wenbit-appearance:none;
  appearance:none;
  width:14px;
  height:var(--height);
  background:#000;
  box-shadow:0px 0px 6px rgba(0,0,0,.15);
  border-radius:2px;
  cursor:ew-resize;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jackie_Mina

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值