css布局实现横向拖动的相片相册胶卷效果代码

代码语言:html

所属分类:画廊相册

代码描述:css布局实现横向拖动的相片相册胶卷效果代码,在pc端可以用键盘方向键左右移动,移动端可直接左右拖动。

代码标签: css 布局 横向 拖动 相片 相册 胶卷

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

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

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

  
<style>
:root {
  --main-bg: #090909;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

html {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

body {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  min-height: 100vh;
  color: #ffffff;
  background-color: var(--main-bg);
  overflow: hidden;
}

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

.wrapper {
  position: relative;
  padding: 28px 0;
  background-color: #333;
  box-shadow: inset 0 2px 10px 0 #000, inset 0 -2px 10px 0 #000,
    inset -8px 0 5px 0 #000, inset -10px 0 9px 0 #fff;
  transform: perspective(1000px) rotateY(10deg);
}

.wrapper::before,
.wrapper::after {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  --width: 12px;
  width: var(--width);
  aspect-ratio: 1/1;
  border-radius: 3px;
  background-color: var(--main-bg);
  box-shadow: calc(var(--width) * 2) 0 var(--main-bg),
    calc(var(--width) * 4) 0 var(--main-bg),
    calc(var(--width) * 6) 0 var(--main-bg),
    calc(var(--width) * 8) 0 var(--main-bg),
    calc(var(--width) * 10) 0 var(--main-bg),
    calc(var(--width) * 12) 0 var(--main-bg),
    calc(var(--width) * 14) 0 var(--main-bg),
    calc(var(--width) * 16) 0 var(--main-bg),
    calc(var(--width) * 18) 0 var(--main-bg),
    calc(var(--width) * 20) 0 var(--main-bg),
    calc(var(--width) * 22) 0 var(--main-bg),
    calc(var(--width) * 24) 0 var(--main-bg);
}

.wrapper::before {
  top: 6px;
}

.wrapper::after {
  bottom: 6px;
}

.list {
  display: flex;
  gap: 20px;
  width: 300px;
  padding: 0 20px;
  overflow-x: scroll;
  list-style: none;
  scroll-snap-type: x mandatory;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.list::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  display: block;
  width: 5px;
  height: 100%;
  background: linear-gradient(to right, transparent, #000);
  /*   backdrop-filter: blur(10px); */
}

.list::-webkit-scrollbar {
  display: none;
}

.list__item {
  flex-shrink: 0;
  width: 120px;
  aspect-ratio: 3/2;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  background-color: #ddd;
  filter: grayscale(1) invert(1) opacity(0.5);
}

.film-can {
  flex-shrink: 0;
  position: relative;
  display: grid;
  width: 120px;
  height: 180px;
  background: linear-gradient(to right, #555 30%, #cccc 80%, #555),
    linear-gradient(to right, #555 30%, #cccc 80%, #555),
    linear-gradient(to right, #555 30%, #cccc 80%, #555);
  border-radius: 0 0 40% 40% / 0 0 7% 7%;
  border-bottom: 4px solid #333;
}

.film-can::before {
  content: "";
  position: absolute;
  top: 5px;
  display: block;
  width: 100%;
  height: 20px;
  background-color: #222;
  border-radius: 0 0 100% 100% / 0 0 100% 100%;
}

.film-can__spool {
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  width: 60px;
  height: 15px;
  background: linear-gradient(to right, #222 30%, #cccc 80%, #222);
  margin-inline: auto;
  border-radius: 0 0 80% 80% / 0 0 30% 30%;
  z-index: 1;
}

.film-can__spool::before {
  content: "";
  display: block;
  width: 100%;
  height: 5px;
  margin-top: -2px;
  background-color: #333;
  border-radius: 100%;
  box-shadow: inset 0 0 5px 0 rgba(0, 0, .........完整代码请登录后点击上方下载按钮下载查看

网友评论0