折叠卡片悬浮详情动画效果

代码语言:html

所属分类:悬停

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


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
*,
*::before,
*::after {
  position: relative;
  box-sizing: border-box;
}

:root {
  --easing: cubic-bezier(.7,0,.3,1);
  --color-red: #E66047;
}

html,
body {
  background: var(--color-red);
  height: 100%;
  display: -webkit-box;
  display: flex;
  -webkit-box-align: center;
          align-items: center;
  -webkit-box-pack: center;
          justify-content: center;
}

#app {
  font-size: 3vmin;
  background: white;
  width: 50vmin;
  height: 90vmin;
  box-shadow: 0 5vmin 8vmin rgba(0, 0, 0, 0.3);
  border-radius: 0.5em;
  overflow: hidden;
  display: grid;
  grid-template: 100% / 100%;
}
#app > [data-view] {
  grid-area: 1 / 1;
  max-height: 100%;
}

/* ---------------------------------- */
[data-view] {
  padding: 1em;
  -webkit-transition: visibility 0s linear, -webkit-transform var(--duration) var(--easing);
  transition: visibility 0s linear, -webkit-transform var(--duration) var(--easing);
  transition: transform var(--duration) var(--easing), visibility 0s linear;
  transition: transform var(--duration) var(--easing), visibility 0s linear, -webkit-transform var(--duration) var(--easing);
}
[data-view]:not([data-active]) {
  visibility: hidden;
  pointer-events: none;
  -webkit-transition-delay: 0s, calc(var(--duration) * 1);
          transition-delay: 0s, calc(var(--duration) * 1);
}
[data-view] .overlay {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.7);
  -webkit-transition: opacity var(--duration) linear;
  transition: opacity var(--duration) linear;
  opacity: 0;
}

/* ---------------------------------- */
[data-view="overview"] .cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 1em;
}
[data-view="overview"] .cards #restaurant {
  grid-column: 1 / -1;
}

.card {
  border-radius: .5em;
  background: var(--color, var(--color-red));
  padding: 1em;
  color: white;
}

#restaurant {
  -webkit-transition: all var(--duration) var(--easing);
  transition: all var(--duration) var(--easing);
  -webkit-transition-property: border-radius, opacity, -webkit-transform;
  transition-property: border-radius, opacity, -webkit-transform;
  transition-property: border-radius, transform, opacity;
  transition-property: border-radius, transform, opacity, -webkit-transform;
  z-index: 2;
  -webkit-transform-origin: top left;
          transform-origin: top left;
}
#restaurant > * {
  opacity: 1;
  -webkit-transition: inherit;
  transition: inherit;
}
#restaurant[data-move="pending"] {
  border-radius: 0;
  -webkit-transition: none;
  transition: none;
  -webkit-transform: translate(calc(var(--dx,0) * -1px), calc(var(--dy,0) * -1px)) scale(var(--dw, 1), var(--dh, 1));
          transform: translate(calc(var(--dx,0) * -1px), calc(var(--dy,0) * -1px)) scale(var(--dw, 1), var(--dh, 1));
}
#restaurant[data-move="pending"] > * {
  opacity: 0;
  -webkit-transition: none;
  transition: none;
}

/* ---------------------------------- */
[data-view="details"] {
  z-index: 2;
  display: grid;
  -webkit-perspective: 800px;
          perspective: 800px;
}
[data-view="details"] .view-content {
  z-index: 2;
  display: grid;
  grid-template: 100% / 100%;
  height: 100%;
  overflow: hidden;
  -webkit-mask-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.2em, transparent), color-stop(4em, #000));
  -webkit-mask-image: linear-gradient(to top, transparent 0.2em, #000 4em);
          mask-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.2em, transparent), color-stop(4em, #000));
          mask-image: linear-gradient(to top, transparent 0.2em, #000 4em);
}
[data-view="details"] .view-content .view-content-container {
  height: 100%;
}
[data-view="details"] .view-content img {
  max-width: 100%;
  height: auto;
}
[data-view="details"] .view-content p {
  font-size: 0.8em;
}
[data-view="details"], [data-view="details"] .fold {
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
}
[data-view="details"] .fold {
  position: absolute;
  top: 99%;
  left: 0;
  height: 102%;
  width: 100%;
  -webkit-transform-origin: top center;
          transform-origin: top center;
  background-color: #fff;
  -webkit-backface-visibility: visible;
          backface-visibility: visible;
}
[data-view="details"] > .fold {
  height: 25%;
  width: 100%;
  top: 0;
  left: 0;
  -webkit-animation: none !important;
          animation: none !important;
}
[data-view="details"] .card {
  position: absolute;
  bottom: 0;
  z-index: 10;
  width: 100%;
  height: 100%;
  opacity: 0;
  border-radius: 0;
}

/* ---------------------------------- */
[data-state="overview"][data-transitioning] [data-view="overview"] #restaurant {
  visibility: hidden;
}
[data-state="overview"][data-transitioning] [data-view="overview"] .overlay {
  opacity: 1;
  -webkit-transition: none;
  transition: none;
}
[data-state="overview"] [data-view="details"] {
  z-index: 2;
  -webkit-animation: slide-down var(--duration) var(--easing) both;
          animation: slide-down var(--duration) var(--easing) both;
  /* Content Clipping Animation */
}
@-webkit-keyframes slide-down {
  from {
    -webkit-transform: none;
            transform: none;
  }
  to {
    -webkit-transform: scale(0.8) translateY(50%);
            transform: scale(0.8) translateY(50%);
  }
}
@keyframes slide-down {
  from {
    -webkit-transform: none;
            transform: none;
  }
  to {
    -webkit-transform: scale(0.8) translateY(50%);
            transform: scale(0.8) translateY(50%);
  }
}
[data-state="overview"] [data-view="details"] .fold {
  --fold-duration: calc( var(--duration) / 4 );
  -webkit-animation: fold-in var(--fold-duration) var(-.........完整代码请登录后点击上方下载按钮下载查看

网友评论0