color-thief实现图片相册列表主色调过滤筛选效果代码
代码语言:html
所属分类:画廊相册
代码描述:color-thief实现图片相册列表主色调过滤筛选效果代码
代码标签: color-thief 图片 相册 列表 主色调 过滤 筛选
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> *, ::before, ::after { margin: 0; padding: 0; box-sizing: border-box; } img { max-width: 100%; display: block; } /* reset button */ button { appearance: none; background-color: transparent; border: none; cursor: pointer; outline: none; padding: 0; margin: 0; font-family: inherit; font-size: inherit; color: inherit; text-decoration: none; text-transform: none; line-height: normal; overflow: visible; } body { min-height: 100svh; padding: 2rem; background-color: #121212; color: white; font-family: system-ui; display: grid; place-content: center; } .wrapper { width: 100%; max-width: 800px; } h1 { font-size: 1.2rem; font-weight: 300; text-align: center; } .filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 1rem; margin-block: 2rem; } .filters input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0; } .filters label { border-radius: 50%; width: 1.5rem; height: 1.5rem; background-color: rgba(var(--c), 1); cursor: pointer; position: relative; outline: 1px solid #ffffff90; outline-offset: 0px; transition: outline 300ms ease-in-out, outline-offset 300ms ease-in-out; } .filters label:hover { outline-style: dashed; outline-offset: 4px; } .filters label:has(input:checked) { outline-offset: 4px; } .filters > button { transition: scale 300ms ease-in-out; border: none; outline: none; width: 2rem; height: 2rem; display: grid; place-content: center; } .filters > button:focus-visible, .filters > button:hover { scale: 1.25; } .image-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr)); margin-inline: auto; gap: 0.25rem; } .image-gallery > div { width: 100%; height: 100%; aspect-ratio: 1; filter: grayscale(0) blur(0px); transition: scale 300ms ease-in-out; } .image-gallery img { width: 100%; height: 100%; object-fit: cover; transition: scale 300ms ease-in-out; border-radius: 5px; } .image-gallery > div.no-match { animation: hideit 300ms linear forwards; pointer-events: none; } .image-gallery > div:not(.no-match):hover { scale: 1.15; z-index: 1; } .hashtag { margin-top: 0.5rem; font-size: 0.8rem; font-weight: 300; text-align: right; width: 100%; border: 1px dashde red; } @keyframes hideit { 25% { filter: grayscale(0) blur(1px); } 50% { filter: grayscale(0) blur(2px); opacity: 1; } 75% { filter: grayscale(0.5) blur(3px); } 100% { filter: grayscale(1) blur(4px); opacity: 0.3; scale: 0.85; } } </style> </head> <body translate="no"> <div class="wrapper"> <!--<h1>Filter Images by Color</h1>--> <div id="filters" class="filters"> <!-- color filter labels loaded here --> <button type="button" id="btn-restore" title="reset all"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-restore"> <path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path d="M3.06 13a9 9 0 1 0 .49 -4.087" /> <path d="M3 4.001v5h5" /> <path d="M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /> </svg> </button> </div> <div id="image-gallery" class="image-gallery"> <!-- images loaded here --> </div> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/color-thief.umd.2.4.0.js"></script> <script > /* * This uses the Color Thief library to extract the colors from the images * https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.4.0/color-thief.umd.js */ const IMGS = [ "https://images.pexels.com/photos/1111369/pexels-photo-1111369.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/1111317/pexels-photo-1111317.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/7997395/pexels-photo-7997395.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/3608294/pexels-photo-3608294.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/165844/noodles-tagliatelle-raw-colorful-165844.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/1329297/pexels-photo-1329297.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/2479238/pexels-photo-2479238.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/957040/night-photograph-starry-sky-night-sky-star-957040.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/1173576/pexels-photo-1173576.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/946255/pexels-photo-946255.jpeg?auto=compress&cs=tinysrgb&w=680&h=375&dpr=1", "https://images.pexels.com/photos/947407/pexels-photo-947407.jpeg?au.........完整代码请登录后点击上方下载按钮下载查看
网友评论0