css实现滚动页面卡片shine时间轴聚焦光感效果代码

代码语言:html

所属分类:加载滚动

代码描述:css实现滚动页面卡片shine时间轴聚焦光感效果代码

代码标签: css 滚动 页面 卡片 shine 时间轴 聚焦 光感

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

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

<head>
  <meta charset="UTF-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1">

  
<style>
@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

@property --x {
  syntax: "<percentage>";
  initial-value: 35%;
  inherits: false;
}

@property --shine {
  syntax: "<color>";
  initial-value: transparent;
  inherits: false;
}

@property --shadow-strength {
  syntax: "<percentage>";
  initial-value: 0%;
  inherits: false;
}

:root {
  --h: 240;
  --s: 97%;
  --l: 50%;
  --surface-1: hsl(var(--h) var(--s) calc(var(--l) + 4%));
  --surface-2: hsl(var(--h) var(--s) calc(var(--l) + 8%));
  --surface-3: hsl(var(--h) var(--s) calc(var(--l) + 12%));
  --text: hsl(var(--h) var(--s) 96%);
  --text-alt: hsl(var(--h) var(--s) 85%);
  --shadow-color: var(--h) var(--s) 15%;
  --shadow-strength: 1%;
  --shadow: 0 -2px 5px 0 hsl(var(--shadow-color) /
          calc(var(--shadow-strength) + 2%)),
    0 1px 1px -2px hsl(var(--shadow-color) / calc(var(--shadow-strength) + 3%)),
    0 2px 2px -2px hsl(var(--shadow-color) / calc(var(--shadow-strength) + 3%)),
    0 5px 5px -2px hsl(var(--shadow-color) / calc(var(--shadow-strength) + 4%)),
    0 9px 9px -2px hsl(var(--shadow-color) / calc(var(--shadow-strength) + 5%)),
    0 16px 16px -2px hsl(var(--shadow-color) / calc(var(--shadow-strength) + 6%));
  --space: 1rem;
}

* {
  box-sizing: border-box;
}

body {
  color: var(--text);
  background: var(--surface-1);
  padding-inline: var(--space);
  font-size: 1.125rem;
  line-height: 1.4;
  font-family: system-ui, sans-serif;
  font-weight: 300;
}

main {
  display: grid;
  gap: 35vh;
}

.page-section {
  container-type: inline-size;
  display: grid;
  gap: var(--space);
  inline-size: min(var(--max, 30rem), 100%);
  margin-inline: auto;
}

.page-footer {
  -webkit-margin-before: 50vh;
          margin-block-start: 50vh;
  text-align: center;
  padding: 2rem;

  h2 {
    display: grid;
  }

  h2::before {
    content: "";
    display: block;
    width: 1px;
    height: 3rem;
    -webkit-margin-after: 0.5rem;
            margin-block-end: 0.5rem;
    margin-inline: auto;
    background: var(--surface-3);
  }
}

.icon {
  width: 2.5rem;
  height: auto;
}

.icon-sm {
  width: 1.5rem;
  color: var(--text-alt);
}

.text-label {
  font-size: 0.8em;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.author {
  text-align: end;
}

.cluster {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-headline {
  --_margin: 30vh;
  -webkit-margin-before: var(--_margin);
          margin-block-start: var(--_margin);
  text-align: center;

  &::after {
    content: "";
    display: block;
    width: 1px;
    height: var(--_margin);
    -webkit-margin-before: 0.8rem;
            margin-block-start: 0.8rem;
    margin-inline: auto;
    background: var(--surface-3);
  }
}

box-gleam {
  --_gleam: linear-gradient(
      115deg,
      transparent 40%,
      var(--surface-3),
      transparent 70%
    )
    var(--x) 0 / 600% 100% padding-box;
  --_gleam-cover: radial-gradient(
      circle at center,
      var(--surface-1),
      transparent
    )
    padding-box;
  --_cover: linear-gradient(var(--surface-1), var(--surface-1)) padding-box;
  --_shine: conic-gradient(
      from var(--angle),
      var(--shine),
      transparent 20% 80%,
      var(--shine)
    )
    border-box;
  --_edges: linear-gradient(
      155deg,
      var(--surface-3),
      var(--surface-2) 20% 80%,
      var(--surface-3)
    )
    border-box;

  display: grid;
  gap: var(--space);
  position: relative;
  padding: 1.6rem;
  border-radius: 0.8rem;
  border: 1px solid transparent;
  box-shadow: var(--shadow);
  background: var(--_gleam-cover), var(--_gleam), var(--_cover), var(--_shine),
    var(--_edges);
}

@supports (animation-timeline: view()) {
  box-gleam {
    -webkit-animation: linear both;
            animation: linear both;
    -webkit-animation-name: gleam, shine, shadow;
            animation-name: gleam, shine, shadow;
    animation-timeline: view();
    animation-range: cover -10% cover 100%, entry 0% cover 65%,
      entry 0% exit 150%;
  }
}

@media (prefers-reduced-motion: reduce) {
  box-gleam {
    -webkit-animation: none !important;
            animation: none !important;
  }
}

@-webkit-keyframes gleam {
  from {
    --angle: -1turn;
    --x: 0%;
  }
  to {
    --angle: 1turn;
    --x: 100%;
  }
}

@keyframes gleam {
  from {
    --angle: -1turn;
    --x: 0%;
  }
  to {
    --angle: 1turn;
    --x: 100%;
  }
}

@-webkit-keyframes shadow {
  from,
  to {
    box-shadow: none;
  }
  50%,
  65% {
    box-shadow: var(--shadow);
  }
}

@keyframes shadow {
  from,
  to {
    box-shadow: none;
  }
  50%,
  65% {
    box-shadow: var(--shadow);
  }
}

@-webkit-keyframes shine {
  0%,
  45% {
    --shine: transparent;
  }
  80% {
    --shine: hsl(var(--h) var(--s) calc(var(--l) + 38%));
  }
}

@keyframes shine {
  0%,
  45% {
    --shine: transparent;
  }
  80% {
    --shine: hsl(var(--h) var(--s) calc(var(--l) + 38%));
  }
}

bento-grid {
  display: grid;
  gap: var(--space);

  > * {
    display: grid;
    place-items: center;
    place-content: center;
    text-align: center;
    padding: 2.5rem;
  }
}

@container (inline-size > 35rem) {
  bento-grid {
    grid-template-columns: repeat(var(--col-count, 3), 1fr);
    grid-template-rows: repeat(var(--row-count, 3), auto);

    > * {
      grid-column: var(--col);
      grid-row: var(--row);
    }
  }
}

/* Check browser support */
.browser-support-text {
  display: none;
}

@supports not (animation-timeline: view()) {
  .browser-support-text {
    display: block;
    color: yellow;
  }
}
</style>


  
  
</head>

<body translate="no">
  <main>
  <section class="page-section">
    <header>
      <h1 class="page-headline text-label">CSS view-timeline shine effect <span class="browser-support-text">⚠️ This browser does not support CSS animation-timeline</span></h1>
    </header>

    <box-gleam>
      <blockquote>
        <p>Fantasy is a necessary ingredient in living, it's a way of looking at life through the wrong end of a telescope.</p>
      </blockquote>
      <p class="author text-label">Dr. Seuss</p>
    </box-gleam>

    <box-gleam>
      <blockquote>
        <p>A day without sunshine is like, you know, night.</p>
      </blockquote>
      <p class="author text-label">Steve Martin</p>
    </box-gleam>

    <box-gleam>
      <blockquote>
        <p>I refuse to answer that question on the grounds that I don't know the answer</p>
      </blockquote>
      <p class="author text-label">Douglas Adams</p>
    </box-gleam>

    <box-gleam>
      <blockquote>
        <p>Whatever the problem, be part of the solution. Don’t just sit around raising questions and pointing out obstacles.</p>
      </blockquote>
      <p class="author text-label">Tina Fey</p>
    </box-gleam>

    <box-gleam>
      <blockquote>
        <p>Never memorize something that you can look up.</p>
      </blockquote>
      <p class="author text-label">Albert Einstein</p>
    </box-gleam>

    <box-gleam>
      <blockquote>
        <p>It’s no use going back to yesterday, because I was a different person then.</p>
      </blockquote>
      <p class="author text-label">Lewis Carroll</p>
    </box-gleam>
  </section>

  <section class="page-section" style="--max: 50rem">
    <bento-grid>
      <box-gleam>
        <svg class="icon" aria-hidden="true" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M11.5 1C11.7761 1 12 1.22386 12 1.5V13.5C12 13.7761 11.7761 14 11.5 14C11.2239 14 11 13.7761 11 13.5V1.5C11 1.22386 11.2239 1 11.5 1ZM9.5 3C9.77614 3 10 3.22386 10 3.5V13.5C10 13.7761 9.77614 14 9.5 14C9.22386 14 9 13.7761 9 13.5V3.5C9 3.22386 9.22386 3 9.5 3ZM13.5 3C13.7761 3 14 3.22386 14 3.5V13.5C14 13.7761 13.7761 14 13.5 14C13.2239 14 13 13.7761 13 13.5V3.5C13 3.22386 13.2239 3 13.5 3ZM5.5 4C5.77614 4 6 4.22386 6 4.5V13.5C6 13.7761 5.77614 14 5.5 14C5.22386 14 5 13.7761 5 13.5V4.5C5 4.22386 5.22386 4 5.5 4ZM1.5 5C1.77614 5 2 5.22386 2 5.5V13.5C2 13.7761 1.77614 14 1.5 14C1.22386 14 1 13.7761 1 13.5V5.5C1 5.22386 1.22386 5 1.5 5ZM7.5 5C7.77614 5 8 5.22386 8 5.5V13.5C8 13.7761 7.77614 14 7.5 14C7.22386 14 7 13.7761 7 13.5V5.5C7 5.22386 7.22386 5 7.5 5ZM3.5 7C3.77614 7 4 7.22386 4 7.5V13.5C4 13.7761 3.77614 14 3.5 14C3.22386 14 3 13.7761 3 13.5V7.5C3 7.22386 3.22386 7 3.5 7Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path>
        </svg>
        <h2 class="text-label">Chart new territory</h2>
      </box-gleam>

      <box-gleam>
        <svg class="icon" aria-hidden="true" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M12.3536 1.14645C12.1583 0.951184 11.8417 0.951184 11.6464 1.14645C11.4512 1.34171 11.4512 1.65829 11.6464 1.85355L12.7929 3H12C10.7037 3 9.71111 3.58423 8.87248 4.38931C8.20065 5.03427 7.59349 5.85684 6.99461 6.6682C6.86287 6.84668 6.73154 7.02462 6.6 7.2C5.10874 9.18835 3.49037 11 0.5 11C0.223858 11 0 11.2239 0 11.5C0 11.7761 0.223858 12 0.5 12C4.00963 12 5.89126 9.81165 7.4 7.8C7.54367 7.60845 7.6832 7.41962 7.81996 7.23454L7.82005 7.23443L7.82006 7.23441C8.41674 6.42695 8.96069 5.69085 9.56502 5.11069C10.2889 4.41577 11.0463 4 12 4H12.7929L11.6464 5.14645C11.4512 5.34171 11.4512 5.65829 11.6464 5.85355C11.8417 6.04882 12.1583 6.04882 12.3536 5.85355L14.3536 3.85355C14.5488 3.65829 14.5488 3.34171 14.3536 3.14645L12.3536 1.14645ZM0.5 3C3.35278 3 5.12992 4.44588 6.50548 6.06746L6.3762 6.24266C6.2483 6.4161 6.12293 6.58609 6 6.75C5.96397 6.79804 5.92798 6.84581 5.892 6.89331C4.57348 5.29306 3.02637 4 0.5 4C0.223858 4 0 3.77614 0 3.5C0 3.22386 0.223858 3 0.5 3ZM8.87248 10.6107C8.37284 10.131 7.90897 9.55314 7.45767 8.95468C7.64688 8.71693 7.82704 8.48061 8 8.25L8.08987 8.12987C8.58412 8.79402 9.05288 9.39766 9.56502 9.88931C10.2889 10.5842 11.0463 11 12 11H12.7929L11.6464 9.85355C11.4512 9.65829 11.4512 9.34171 11.6464 9.14645C11.8417 8.95118 12.1583 8.95118 12.3536 9.14645L14.3536 11.1464C14.5488 11.3417 14.5488 11.6583 14.3536 11.8536L12.3536 13.8536C12.1583 14.0488 11.8417 14.0488 11.6464 13.8536C11.4512 13.6583 11.4512 13.3417 11.6464 13.1464L12.7929 12H12C10.7037 12 9.71111 11.4158 8.87248 10.6107Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path>
        </svg>
        <h2 class="text-label">Shuffle the beat</h2>
      </box-gleam>

      <box-gleam style="--row: span 3">
        <svg class="icon" aria-hidden="true" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M6.85357 3.85355L7.65355 3.05353C8.2981 2.40901 9.42858 1.96172 10.552 1.80125C11.1056 1.72217 11.6291 1.71725 12.0564 1.78124C12.4987 1.84748 12.7698 1.97696 12.8965 2.10357C13.0231 2.23018 13.1526 2.50125 13.2188 2.94357C13.2828 3.37086 13.2779 3.89439 13.1988 4.44801C13.0383 5.57139 12.591 6.70188 11.9464 7.34645L7.49999 11.7929L6.35354 10.6465C6.15827 10.4512 5.84169 10.4512 5.64643 10.6465C5.45117 10.8417 5.45117 11.1583 5.64643 11.3536L7.14644 12.8536C7.34171 13.0488 7.65829 13.0488 7.85355 12.8536L8.40073 12.3064L9.57124 14.2572C9.65046 14.3893 9.78608 14.4774 9.9389 14.4963C10.0917 14.5151 10.2447 14.4624 10.3535 14.3536L12.3535 12.3536C12.4648 12.2423 12.5172 12.0851 12.495 11.9293L12.0303 8.67679L12.6536 8.05355C13.509 7.19808 14.0117 5.82855 14.1887 4.58943C14.2784 3.9618 14.2891 3.33847 14.2078 2.79546C14.1287 2.26748 13.9519 1.74482 13.6035 1.39645C13.2552 1.04809 12.7325 0.871332 12.2045 0.792264C11.6615 0.710945 11.0382 0.721644 10.4105 0.8113C9.17143 0.988306 7.80189 1.491 6.94644 2.34642L6.32322 2.96968L3.07071 2.50504C2.91492 2.48278 2.75773 2.53517 2.64645 2.64646L0.646451 4.64645C0.537579 4.7.........完整代码请登录后点击上方下载按钮下载查看

网友评论0