css实现手机移动设备图片堆叠拖拽切换效果代码

代码语言:html

所属分类:拖放

代码描述:css实现手机移动设备图片堆叠拖拽切换效果代码,电脑端不支持拖拽。

代码标签: css 手机 移动 设备 图片 堆叠 拖拽 切换

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

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

<head>
  <meta charset="UTF-8">
  
  
  
  
<style>
@charset "UTF-8";
:root {
  font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  font-weight: 400;
  --dim-card-width: 300px;
  --dim-card-height: 400px;
  --dim-card-border-radius: 16px;
  --box-shadow-card: 0 1px 12px rgba(0, 0, 0, 0.4);
}

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

* {
  box-sizing: border-box;
}

body,
html {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ddd;
  height: 100vh;
  min-height: 800px;
  timeline-scope: --scroll-timeline;
  animation: theme-bg linear forwards;
  animation-timeline: --scroll-timeline;
}

main {
  width: 800px;
  height: 600px;
  perspective: 1000px;
  transform-style: preserve-3d;
}

.scroller {
  width: 100%;
  height: 100%;
  overflow: auto;
  white-space: nowrap;
  display: flex;
  scroll-snap-type: x mandatory;
  scroll-timeline: --scroll-timeline;
  scroll-timeline-axis: x;
}

.scroll-item {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: start;
}

[data-debug=true] .scroll-item {
  outline: 1px dashed magenta;
}

.card-stack {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.card {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: auto;
  width: var(--dim-card-width);
  height: var(--dim-card-height);
  border-radius: var(--dim-card-border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
  overflow: hidden;
  background-color: rgba(255, 255, 255, 0.8);
  box-shadow: var(--box-shadow-card);
}

.card img {
  position: absolute;
  object-fit: cover;
  width: 100%;
  z-index: 1;
  height: 100%;
}

.card::before {
  position: absolute;
  top: -4px;
  bottom: -4px;
  right: -4px;
  left: -4px;
  content: "";
}

.card:nth-child(1) {
  animation: animate1-inactive linear forwards;
  animation-timeline: --scroll-timeline;
}

[data-active-index="0"] .card:nth-child(1) {
  animation: animate1-active linear forwards;
  animation-timeline: --scroll-timeline;
}

.card:nth-child(1) img {
  animation: animate-card-image-1 linear forwards;
  animation-timeline: --scroll-timeline;
}

[data-active-index="0"] .card-stack {
  animation: card-stack-1 linear forwards;
  animation-timeline: --scroll-timeline;
}

.card:nth-child(1)::before {
  animation: card-bg linear forwards;
  animation-timeline: --scroll-timeline;
}

@keyframes animate1-active {
  0% {
    transform: translateX(0) rotateY(0) rotateZ(0) rotateX(0) translateZ(0);
  }
  12.5% {
    transform: translateX(-116%) rotateY(-24deg) rotateZ(0) rotateX(2deg) translateZ(-156px);
  }
  25% {
    transform: translateX(-11%) rotateY(0) rotateZ(-6deg) rotateX(0) translateZ(-160px);
  }
  50% {
    transform: translateX(-19%) rotateY(0) rotateZ(-8deg) rotateX(0) translateZ(-180px);
  }
  75% {
    transform: translateX(-27%) rotateY(0) rotateZ(-10deg) rotateX(0) translateZ(-200px);
  }
  100% {
    transform: translateX(-35%) rotateY(0) rotateZ(-12deg) rotateX(0) translateZ(-220px);
  }
}
@keyframes animate1-inactive {
  0% {
    transform: translateX(0) rotateY(0) rotateZ(0) rotateX(0) translateZ(0);
  }
  25% {
    transform: translateX(-11%) rotateY(0) rotateZ(-6deg) rotateX(0) translateZ(-160px);
  }
  50% {
    transform: translateX(-19%) rotateY(0) rotateZ(-8deg) rotateX(0) translateZ(-180px);
  }
  75% {
    transform: translateX(-27%) rotateY(0) rotateZ(-10deg) rotateX(0) translateZ(-200px);
  }
  100% {
    transform: translateX(-35%) rotateY(0) rotateZ(-12deg) rotateX(0) translateZ(-220px);
  }
}
@keyframes animate-card-image-1 {
  0% {
    opacity: 1;
  }
  25% {
    opacity: 0.3333333333;
  }
  50% {
    opacity: 0.1111111111;
  }
  75% {
    opacity: 0.037037037;
  }
  100% {
    opacity: 0.012345679;
  }
}
@keyframes card-stack-1 {
  0% {
    transform: rotateY(0deg);
  }
  12.5% {
    transform: rotateY(24deg) translateZ(24deg);
  }
  12.5% {
    transform: rotateY(-24deg);
  }
  25% {
    transform: rotateY(0deg);
  }
  37.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
  37.5% {
    transform: rotateY(-24deg);
  }
  50% {
    transform: rotateY(0deg);
  }
  62.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
  62.5% {
    transform: rotateY(-24deg);
  }
  75% {
    transform: rotateY(0deg);
  }
  87.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
  87.5% {
    transform: rotateY(-24deg);
  }
  100% {
    transform: rotateY(0deg);
  }
  112.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
}
.card:nth-child(2) {
  animation: animate2-inactive linear forwards;
  animation-timeline: --scroll-timeline;
}

[data-active-index="1"] .card:nth-child(2) {
  animation: animate2-active linear forwards;
  animation-timeline: --scroll-timeline;
}

.card:nth-child(2) img {
  animation: animate-card-image-2 linear forwards;
  animation-timeline: --scroll-timeline;
}

[data-active-index="1"] .card-stack {
  animation: card-stack-2 linear forwards;
  animation-timeline: --scroll-timeline;
}

.card:nth-child(2)::before {
  animation: card-bg linear forwards;
  animation-timeline: --scroll-timeline;
}

@keyframes animate2-active {
  0% {
    transform: translateX(11%) rotateY(0) rotateZ(6deg) rotateX(0) translateZ(-160px);
  }
  12.5% {
    transform: translateX(116%) rotateY(24deg) rotateZ(0) rotateX(2deg) translateZ(-156px);
  }
  25% {
    transform: translateX(0) rotateY(0) rotateZ(0) rotateX(0) translateZ(0);
  }
  37.5% {
    transform: translateX(-116%) rotateY(-24deg) rotateZ(0) rotateX(2deg) translateZ(-156px);
  }
  50% {
    transform: translateX(-11%) rotateY(0) rotateZ(-6deg) rotateX(0) translateZ(-160px);
  }
  75% {
    transform: translateX(-19%) rotateY(0) rotateZ(-8deg) rotateX(0) translateZ(-180px);
  }
  100% {
    transform: translateX(-27%) rotateY(0) rotateZ(-10deg) rotateX(0) translateZ(-200px);
  }
}
@keyframes animate2-inactive {
  0% {
    transform: translateX(11%) rotateY(0) rotateZ(6deg) rotateX(0) translateZ(-160px);
  }
  25% {
    transform: translateX(0) rotateY(0) rotateZ(0) rotateX(0) translateZ(0);
  }
  50% {
    transform: translateX(-11%) rotateY(0) rotateZ(-6deg) rotateX(0) translateZ(-160px);
  }
  75% {
    transform: translateX(-19%) rotateY(0) rotateZ(-8deg) rotateX(0) translateZ(-180px);
  }
  100% {
    transform: translateX(-27%) rotateY(0) rotateZ(-10deg) rotateX(0) translateZ(-200px);
  }
}
@keyframes animate-card-image-2 {
  0% {
    opacity: 0.3333333333;
  }
  25% {
    opacity: 1;
  }
  50% {
    opacity: 0.3333333333;
  }
  75% {
    opacity: 0.1111111111;
  }
  100% {
    opacity: 0.037037037;
  }
}
@keyframes card-stack-2 {
  0% {
    transform: rotateY(0deg);
  }
  12.5% {
    transform: rotateY(24deg) translateZ(24deg);
  }
  12.5% {
    transform: rotateY(24deg);
  }
  25% {
    transform: rotateY(0deg);
  }
  37.5% {
    transform: rotateY(24deg) translateZ(24deg);
  }
  37.5% {
    transform: rotateY(-24deg);
  }
  50% {
    transform: rotateY(0deg);
  }
  62.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
  62.5% {
    transform: rotateY(-24deg);
  }
  75% {
    transform: rotateY(0deg);
  }
  87.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
  87.5% {
    transform: rotateY(-24deg);
  }
  100% {
    transform: rotateY(0deg);
  }
  112.5% {
    transform: rotateY(-24deg) translateZ(-24deg);
  }
}
.card:nth-child(3) {
  animation: animate3-inactive linear forwards;
  animation-timeline: --scroll-timeline;
}

[data-active-index="2"] .card:nth-child(3) {
  animation: animate3-active linear forwards;
  animation-timeline: --scroll-timeline;
}

.card:nth-child(3) img {
  animation: animate-card-image-3 linear forwards;
  animation-timeline: --scroll-timeline;
}

[data-active-index="2"] .card-stack {
  animation: card-stack-3 linear forwards;
  animation-timeline: --scroll-timeline;
}

.card:nth-child(3)::before {
  animation: card-bg linear forwards;
  animation-timeline: --scroll-timeline;
}

@keyframes animate3-active {
  0% {
    transform: translateX(19%) rotateY(0) rotateZ(8deg) rotateX(0) translateZ(-180px);
  }
  25% {
    transform: translateX(11%) rotateY(0) rotateZ(6deg) rotateX(0) translateZ(-160px);
  }
  37.5% {
    transform: translateX(116%) rotateY(24deg) rotateZ(0) rotateX(2deg) translateZ(-156px);
  }
  50% {
    transform: translateX(0) rotateY(0) rotateZ(0) rotateX(0) translateZ(0);
  }
  62.5% {
    transform: translateX(-116%) rotateY(-24deg) rotateZ(0) rotateX(2deg) translateZ(-156px);
  }
  75% {
    transform: translateX(-11%) rotateY(0) rotateZ(-6deg) rotateX(0) translateZ(-160px);
  }
  100% {
    transform: translateX(-19%) rotateY(0) rotateZ(-8deg) rotateX(0) translateZ(-180px);
  }
}
@keyframes animate3-inactive {
  0% {
    transform: translateX(19%) rotateY(0) rotateZ(8deg) rotateX(0) translateZ(-180px);
  }
  25% {
    transform: translateX(11%) rotateY(0) rotateZ(6deg) rotateX(0) translateZ(-160px);
  }
  50% {
    transform: translateX(0) rotateY(0) rotateZ(0) rotateX(0) translateZ(0);
  }
  75% {
    transform: translateX(-11%) rotateY(0) rotateZ(-6deg) rotateX(0) translateZ(-160px);
  }
  100% {
    transform: translateX(-19%) rotateY(0) rotateZ(-8deg) rotateX(0) translateZ(-180px);
  }
}
@keyframes animate-card-image-3 {
  0% {
    opacity: 0.1111111111;
  }
  25% {
    opacity: 0.3333333333;
  }
  50% {
    opacity: 1;
  }
  75% {
    opacity: 0.3333333333;
  }
  100% {
    opacity: 0.1111111111;
  }
}
@keyframes card-stack-3 {
  0% {
    transform: rotateY(0deg);
  }
  12.5% {
    transform: rotateY(24deg) translateZ(24deg);
  }
  12.5% {
    transform: rotateY(24deg);
  }
  25% {
    trans.........完整代码请登录后点击上方下载按钮下载查看

网友评论0