js+css实现页面滚动驱动齿轮转动动画效果代码

代码语言:html

所属分类:加载滚动

代码描述:js+css实现页面滚动驱动齿轮转动动画效果代码

代码标签: js css 页面 滚动 驱动 齿轮 转动 动画

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

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

<head>
  <meta charset="UTF-8">
  
  
  
<style>
@import url('https://fonts.googleapis.com/css2?family=Gloria+Hallelujah&display=swap');


@layer normalize, base, demo;

@layer demo {
  body {
    height: 500vh;
  }

  html {
    color-scheme: light dark;
  }

  [data-theme='light'] {
    color-scheme: light only;
  }

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

  .arrow {
    position: fixed;
    left: 9rem;
    top: 12rem;
    width: 70px;
    z-index: 9999;
  }

  .arrow svg {
    width: 70px;
    scale: -1 1;
  }

  .arrow label {
    font-family: 'Gloria Hallelujah', cursive;
    position: absolute;
    left: 110%;
    top: 50%;
  }

  h1 {
    --font-level: 5;
    position: fixed;
    top: 50%;
    left: 50%;
    translate: -50% -50%;
    margin: 0;
    white-space: nowrap;
  }

  .gears {
    width: 100px;
    aspect-ratio: 1 / 2;
    position: fixed;
    top: 5.5rem;
    left: 1.5rem;
    container-type: inline-size;
  }

  .gears__box {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: light-dark(hsl(0 0% 15%), hsl(0 0% 0%));
  }

  .gears::before {
    content: '';
    position: absolute;
    inset: -10px;
    z-index: -1;
    background: radial-gradient(
          circle at center,
          light-dark(hsl(0 0% 75%), hsl(0 0% 50%)) 2px,
          transparent 2px
        )
        50% 50% / 54px 52px,
      color-mix(in lch, canvas, hsl(0 0% 100% / 0.2));
  }

  .gears::after {
    content: '';
    position: absolute;
    inset: 0;
    background: hsl(0 0% 100% / 0.2);
    -webkit-mask: linear-gradient(
      135deg,
      #0000 30%,
      #000 20% 40%,
      #0000 40% 45%,
      #000 45% 50%,
      #0000 50%
    );
            mask: linear-gradient(
      135deg,
      #0000 30%,
      #000 20% 40%,
      #0000 40% 45%,
      #000 45% 50%,
      #0000 50%
    );
    -webkit-backdrop-filter: blur(1px);
            backdrop-filter: blur(1px);
  }

  .gears svg path {
    stroke: light-dark(hsl(0 0% 75%), hsl(0 0% 50%));
  }

  .gears svg {
    position: absolute;
    -webkit-animation: rotate linear both;
            animation: rotate linear both;
    animation-timeline: scroll(root);
    --rotation: 720;
    aspect-ratio: 1;
  }

  .gears svg:nth-of-type(1) {
    width: 150cqi;
    left: 0;
    top: 0;
    translate: -50% -50%;
    --turn: calc(var(--rotation) * (10 / 16) * -1deg);
    color: hsl(0 0% 35%);
  }
  .gears svg:nth-of-type(2) {
    width: calc(150cqi * (5 / 8));
    translate: 42% 42%;
    top: 0;
    left: 0;
    rotate: 8deg;
    --turn: calc(var(--rotation) * 1deg);
    color: hsl(0 0% 45%);
  }
  .gears svg:nth-of-type(3) {
    width: 150cqi;
    top: 50%;
    left: 0;
    rotate: 2deg;
    translate: -42% 2%;
    --turn: calc(var(--rotation) * (10 / 16) * -1deg);
    color: hsl(0 0% 40%);
  }
  .gears svg:nth-of-type(4) {
    display: none;
  }

  @-webkit-keyframes rotate {
    to {
      transform: rotate(var(--turn, 360deg));
    }
  }

  @keyframes rotate {
    to {
      transform: rotate(var(--turn, 360deg));
    }
  }
}

@layer base {
  :root {
    --font-size-min: 16;
    --font-size-max: 20;
    --font-ratio-min: 1.2;
    --font-ratio-max: 1.33;
    --font-width-min: 375;
    --font-width-max: 1500;
  }

  :where(.fluid) {
    --fluid-min: calc(
      var(--font-size-min) * pow(var(--font-ratio-min), var(--font-level, 0))
    );
    --fluid-max: calc(
      var(--font-size-max) * pow(var(--font-ratio-max), var(--font-level, 0))
    );
    --fluid-preferred: calc(
      (var(--fluid-max) - var(--fluid-min)) /
        (var(--font-width-max) - var(--font-width-min))
    );
    --fluid-type: clamp(
      (var(--fluid-min) / 16) * 1rem,
      ((var(--fluid-min) / 16) * 1rem) -
        (((var(--fluid-preferred) * var(--font-width-min)) / 16) * 1rem) +
        (var(--fluid-preferred) * var(--variable-unit, 100vi)),
      (var(--fluid-max) / 16) * 1rem
    );
    font-size: var(--fluid-type);
  }

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

  body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
      Helvetica, Arial, sans-serif, system-ui;
  }

  body::before {
    --size: 45px;
    --line: color-mix(in lch, canvasText, transparent 70%);
    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(--.........完整代码请登录后点击上方下载按钮下载查看

网友评论0