css实现多种filter图片对比效果代码

代码语言:html

所属分类:布局界面

代码描述:css实现多种filter图片对比效果代码,一共7种效果,点击底部图标进行切换。

代码标签: css 多种 filter 图片 对比

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

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

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

<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/normalize.css">

  
  
<style>
@charset "UTF-8";
:root {
  --tra: all 0.5s ease 0s;
  --icon: #222;
}

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  font-family: Arial, Helvetica, serif;
  background: radial-gradient(circle at 50% 0%, #000, #333);
}

body:before {
  content: "IMAGES FROM UNSPLASH.COM";
  position: absolute;
  color: #fff0;
  left: 50%;
  transform: translateX(-50%);
  text-shadow: 0 1px 1px #333d, 0 -1px 1px #ffffff82;
  font-family: Arial, serif;
  font-size: 1.3vmin;
  margin-top: -90vmin;
}

body * {
  box-sizing: border-box;
}

.comparsion {
  width: 40vmin;
  height: 30vmin;
  position: relative;
  transform: scale(2.25);
  box-shadow: 0 0 0 1vmin #fff;
  margin-top: -8vmin;
}

.comparsion > div {
  background: url(//repo.bfw.wiki/bfwrepo/image/5d6539613d08b.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_800,h_600,/quality,q_90) no-repeat 0 0;
  background-size: cover;
  width: 100%;
  height: 100%;
  position: absolute;
}

.filtered {
  filter: sepia(0.9);
}

.comparsion > .original {
  width: calc(50% + 2px);
  resize: horizontal;
  overflow: hidden;
  max-width: calc(40vmin - 1.35vmin);
  border-right: 0.325vmin solid #0008;
}

div::-webkit-resizer {
  background: linear-gradient(135deg, #fff0 0 1.5vmin, #fff 0 1.7vmin, #fff0 0 1.9vmin, #fff 0 2.1vmin, #fff0 0 2.3vmin, #fff 0 2.5vmin, #fff0 0 2.7vmin, #fff 0 100%);
}

label, a.reload {
  position: absolute;
  margin-top: 85vmin;
  background: #444;
  width: 5vmin;
  height: 5vmin;
  cursor: pointer;
  border-radius: 0.15vmin;
  margin-left: -43vmin;
}

label:hover {
  background: #fffc;
}

label + label {
  margin-left: -25vmin;
}

label + label + label {
  margin-left: -7vmin;
}

label + label + label + label {
  margin-left: 11vmin;
}

label + label + label + label + label {
  margin-left: 29vmin;
}

label + label + label + label + label + label {
  margin-left: 47vmin;
}

label + label + label + label + label + label + label {
  margin-left: 65vmin;
}

input {
  display: none;
}

input#grayscale:checked ~ .comparsion .filtered {
  filter: grayscale(1);
}

input#color:checked ~ .comparsion .filtered {
  filter: hue-rotate(45deg);
}

input#saturate:checked ~ .comparsion .filtered {
  filter: saturate(3);
}

input#brightness:checked ~ .comparsion .filtered {
  filter: brightness(2);
}

input#contrast:checked ~ .comparsion .filtered {
  filter: contrast(3);
}

input#invert:checked ~ .comparsion .filtered {
  filter: invert(1);
}

input#sepia:checked ~ label[for=sepia],
input#grayscale:checked ~ label[for=grayscale],
input#color:checked ~ label[for=color],
input#saturate:checked ~ label[for=saturate],
input#brightness:checked ~ label[for=brightness],
input#contrast:checked ~ label[for=contrast],
input#invert:checked ~ label[for=invert] {
  background: #fff;
  cursor: default;
}

input#sepia:checked ~ label[for=sepia]:after,
input#grayscale:checked ~ label[for=grayscale]:after,
input#color:checked ~ label[for=color]:after,
input#saturate:checked ~ label[for=saturate]:after,
input#brightness:checked ~ label[for=brightness]:after,
input#contrast:checked ~ label[for=contrast]:after,
input#invert:checked ~ label[for=invert]:after {
  bottom: 6vmin;
  opacity: 1;
  width: 160%;
  margin-left: -30%;
  transition-timing-function: cubic-bezier(0.68, -0.55, 0, 1.94);
}

a.reload {
  margin-left: -61vmin;
  background: #444;
  text-decoration: none;
}

a.reload:hover {
  background: #fff;
}

a.reload:before {
  --ar: #282828;
  content: "";
  position: absolute;
  width: 5vmin;
  height: 5vmin;
  border-radius: 100%;
  transform: rotate(0deg);
  background: radial-gradient(circle at 50% 135%, #fff0 35%, var(--ar) calc(35% + 1px) 45%, #fff0 calc(45% + 1px) 100%), radial-gradient(circle at 50% -35%, #fff0 35%, var(--ar) calc(35% + 1px) 45%, #fff0 calc(45% + 1px) 100%), conic-gradient(from -45deg at 50% 60%, var(--ar) 0 25%, #fff0 0 100%), conic-gradient(from 135deg at 50% 40%, var(--ar) 0 25%, #fff0 0 100%);
  background-size: 100% 25%, 100% 25%, 1.5vmin 1.5vmin, 1.5vmin 1.5vmin;
  background-repeat: no-repeat;
  background-position: 0% 17%, 0% 83%, 77% 50%, 23% 50%;
  transition: var(--tra);
}

a.reload:hover:before {
  transform: rotate(360deg);
}

a.reload:after, label:after {
  content: "RELOAD IMAGE";
  position: absolute;
  width: 100%;
  height: 1.55vmin;
  text-align: center;
  font-size: 1.15vmin;
  font-weight: bold;
  padding: 0.5vmin 0 1vmin;
  background: conic-gradient(from -45deg at 50% 100%, #fff 0 25%, #fff0 0 100%), linear-gradient(0deg, #fff0 0.825vmin, #fff 0 100%);
  left: 0vmin;
  z-index: -1;
  bottom: 0;
  opacity: 0;
  transition: var(--tra);
  color: #212121;
}

a.reload:hover:after, label:hover:after {
  bottom: 6vmin;
  opacity: 1;
  width: 160%;
  margin-left: -30%;
  transition-timing-function: cubic-bezier(0.68, -0.55, 0, 1.94);
  opacity: 0.75;
}

a.reload:hover:after {
  width: 200%;
  margin-left: -50%;
}

a.reload > span:after {
  content: " FILTERS    ➜";
  font-size: 1.1vmin;
  position: absolute;
  top: -3.5vmin;
  color: #666;
  font-weight: bold;
  z-index: -1;
  width: 150%;
  left: 0%;
}

label:before {
  position: absolute;
  color: #555;
  font-size: 1.2vmin;
  width: 160%;
  margin-left: -30%;
  text-align: center;
  top: -3.5vmin;
  font-weight: bold;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0