tweakpane+splitting实现可调参数的页面滚动文字字母模糊入场动画代码

代码语言:html

所属分类:加载滚动

代码描述:tweakpane+splitting实现可调参数的页面滚动文字字母模糊入场动画代码,滚动鼠标滚轮试试看。

代码标签: tweakpane splitting 参数 页面 滚动 文字 字母 模糊 入场 动画 代码

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

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

<head>
  <meta charset="UTF-8">
  
  
  
<style>
@import url('https://fonts.googleapis.com/css2?family=Enriqueta:wght@400;500;600;700&display=swap');
@import 'normalize.css';

@property --sleep {
  inherits: true;
  syntax: '<number>';
  initial-value: 0;
}

*,
*:after,
*:before {
  box-sizing: border-box;
}

:root {
  --sleep-buffer: 200;
}

[data-theme='light'],
html {
  --strength: 0.15;
  color-scheme: light only;
}

@media (prefers-color-scheme: dark) {
  html {
    --strength: 1;
    color-scheme: dark only;
  }
}

[data-theme='dark'] {
  --strength: 1;
  color-scheme: dark only;
}

.word {
  white-space: nowrap;
}

header img {
  position: absolute;
  top: 0%;
  z-index: -1;
  left: 0;
  width: 80vh;
  translate: -30% 0%;
  aspect-ratio: 1;
  -o-object-fit: cover;
     object-fit: cover;
  filter: grayscale(1);
  mix-blend-mode: difference;
  -webkit-mask: linear-gradient(-45deg, #0000, #000, #0000),
    linear-gradient(-90deg, #0000, #000, #0000),
    radial-gradient(circle at center, #000, hsl(0 0% 100% / 0.5), #0000 70%);
          mask: linear-gradient(-45deg, #0000, #000, #0000),
    linear-gradient(-90deg, #0000, #000, #0000),
    radial-gradient(circle at center, #000, hsl(0 0% 100% / 0.5), #0000 70%);
  -webkit-mask-composite: source-in, xor;
          mask-composite: intersect;
}

body {
  display: flex;
  flex-direction: column;
  place-items: center;
  min-height: 100vh;
  font-family: 'Enriqueta', serif;
  overflow-x: hidden;
  background: linear-gradient(
    -30deg,
    transparent,
    hsl(0 0% 0% / var(--strength, 0.05)) 10% 15%,
    transparent 30% 50%,
    hsl(0 0% 0% / var(--strength, 0.05)) 70% 75%,
    transparent
  );
  background-attachment: fixed;
}

body::before {
  --size: 40px;
  --line: color-mix(in lch, canvasText, transparent 85%);
  content: '';
  height: 100vh;
  width: 100vw;
  position: fixed;
  background: linear-gradient(
        90deg,
        var(--line) 1px,
        transparent 1px var(--size)
      )
      50% 50% / var(--size) var(--size),
    linear-gradient(var(--line) 1px, transparent 1px var(--size)) 50% 50% /
      var(--size) var(--size);
  -webkit-mask: linear-gradient(-25deg, transparent 30%, white);
          mask: linear-gradient(-25deg, transparent 30%, white);
  top: 0;
  transform-style: flat;
  pointer-events: none;
  z-index: -1;
}

main {
  width: 100%;
}

header {
  min-height: 10vh;
  display: flex;
  place-items: center;
  width: 60ch;
  max-width: calc(100% - 2rem);
  padding: 1rem;
}

header h1 {
  width: auto;
  font-size: clamp(2.5rem, 4vw + 1rem, 8rem);
  font-weight: 400;
  margin: 0;
  text-wrap: balance;
  display: grid;
  translate: 0 -0.4em;
}

header h1 span {
  font-size: 0.4em;
  font-weight: 600;
  font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
    Helvetica, Arial, sans-serif, system-ui;
  color: hsl(15 80% 50%);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme='light']) header img {
    filter: brightness(0.5) contrast(1.25);
  }
}

section:first-of-type p {
  max-width: calc(100vw - 2rem);
  width: 34ch;
  text-align: center;
  font-size: clamp(1.5rem, 2.25vw + 1rem, 6rem);
  font-weight: 400;
}

section:last-of-type {
  height: 100vh;
  display: grid;
  place-items: center;
  font-size: clamp(2.5rem, 6vw + 1rem, 8rem);
}

p {
  margin: 0;
}

.squisher {
  display: inline-block;
  position: relative;
  line-height: 0.85;
}

.squisher > [aria-hidden='true'] {
  position: absolute;
  inset: 0;
}

.squisher span:nth-of-type(1) {
  transform-origin: 50% 100%;
}

.squisher span:nth-of-type(2) {
  transform-origin: 50% 0;
}

.squisher span:nth-of-type(3) {
  color: transparent;
}

section:first-of-type div {
  position: sticky;
  height: 100vh;
  top: 0;
  display: grid;
  place-items: center;
}

footer {
  padding: 2rem;
}

.bear-link {
  color: canvasText;
  position: fixed;
  top: 1rem;
  left: 1rem;
  width: 48px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  opacity: 0.8;
}

:where(.x-link, .bear-link):is(:hover, :focus-visible) {
  opacity: 1;
}

.bear-link svg {
  width: 75%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.char {
  display: inline-block;
}

div.tp-dfwv {
  position: fixed;
}

@supports (animation-timeline: scroll()) {
  [data-entity='character'] section:first-of-type {
    /* min-height: 200vh; */
    view-timeline: --section;
    height: calc(
      100vh + (var(--scroll-padding) * 2px) + (var(--sleep-buffer) * 1px) +
        (
          (
              var(--char-total) *
                (var(--pixels-per-character) * var(--delay-multiplier))
            ) * 1px
        )
    );
  }

  [data-entity='word'] section:first-of-type {
    /* min-height: 200vh; */
    view-timeline: --section;
    height: calc(
      100vh + (var(--scroll-padding) * 2px) + (var(--sleep-buffer) * 1px) +
        (
          (
              var(--word-total) *
                (var(--pixels-per-character) * var(--delay-multiplier))
            ) * 1px
        )
    );
  }

  [data-entity='character'] .char {
    /* To calculate a delay, use "sin" against the entire range of the start? */
    /* calc(sin((var(--index) / 12) * 45deg) * 0.475s); */
    --start: calc(
      100vh + (var(--scroll-padding) * 1px) +
        (
          (
              sin((var(--char-index) / var(--char-total)) * 45deg) *
                (
                  var(--char-total) *
                    (var(--pixels-per-character) * var(--delay-multiplier))
                )
            ) * 1px
        )
    );
    --end: calc(var(--start) + (var(--pixels-per-character) * 1px));
    -webkit-animation: drop both linear;
            animation: drop both linear;
    animation-timeline: --section;
    animation-range: var(--start) var(--end);
  }

  [data-entity='word'] .word {
    /* To calculate a delay, use "sin" against the entire range of the start? */
    /* calc(sin((var(--index) / 12) * 45deg) * 0.475s); */
    display: inline-block;
    --start: calc(
      100vh + (var(--scroll-padding) * 1px) +
        (
          (
              sin((var(--word-index) / var(--word-total)) * 45deg) *
                (
                  var(--word-total) *
                    (var(--pixels-per-character) * var(--delay-multiplier))
                )
            ) * 1px
        )
    );
    --end: calc(var(--start) + (var(--pixels-per-character) * 1px));
    -webkit-animation: drop both linear;
            animation: drop both linear;
    animation-timeline: --section;
    animation-range: var(--start) var(--end);
  }

  @-webkit-keyframes drop {
    0% {
      translate: calc(var(--x, 0) * 1%) calc(var(--y, 0) * 1%);
      filter: blur(calc(var(--blur, 6) * 1px));
      opacity: 0;
    }
  }

  @keyframes drop {
    0% {
      translate: calc(var(--x, 0) * 1%) calc(var(--y, 0) * 1%);
      filter: blur(calc(var(--blur, 6) * 1px));
      opacity: 0;
    }
  }

  section:has(.squisher) {
    view-timeline-name: --squisher;
  }

  .squisher span:nth-of-type(2) {
    --from: 1 1;
    --to: 1 0;
  }

  .squisher span:nth-of-type(1) {
    --from: 1 0;
    --to: 1 1;
  }

  .squisher span[aria-hidden='true'] {
    -webkit-animation: scale both ease-in-out;
            animation: scale both ease-in-out;
    animation-timeline: --squisher;
    animation-range: entry calc(100% - 10vh) entry 100%;
  }

  @-webkit-keyframes scale {
    to {
      scale: 10;
    }
  }

  @keyframes scale {
    to {
      scale: 10;
    }
  }

  @keyframes scale {
    0% {
      scale: var(--from);
    }

    100% {
      scale: var(--to);
    }
  }

  header {
    view-timeline-name: --header;
  }

  .header__content {
    translate: 0 200%;
  }

  header :where(img, h1) {
    -webkit-animation: fade-away both linear;
            animation: fade-away both linear;
    animation-timeline: --header;
    animation-range: exit 100%.........完整代码请登录后点击上方下载按钮下载查看

网友评论0