gsap+shiki+matter实现代码点击自由落体闪落一地动画效果代码

代码语言:html

所属分类:动画

代码描述:gsap+shiki+matter实现代码点击自由落体闪落一地动画效果代码

代码标签: gsap shiki matter 代码 点击 自由 落体 闪落 一地 动画

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

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

<head>
  <meta charset="UTF-8">
  
<style>
@import url("//repo.bfw.wiki/bfwrepo/css/normalize.min.css") layer(normalize);

@layer normalize, base, demo;

@layer demo {
  @counter-style pad-example {
    system: extends decimal;
    suffix: ' ';
    pad: 2 ' ';
  }
  main pre {
    margin: 0;
    counter-set: line;
    padding: 1.2rem;
    font-size: 0.875rem;
    background: black !important;
    filter: grayscale(1);
    margin: 0;
  }
  main {
    position: relative;
  }

  main:not([data-active='true']) {
    cursor: not-allowed;
  }

  code {
    background: black;
    display: flex;
    flex-direction: column;
  }
  [data-active='true'] .character {
    cursor: -webkit-grab;
  }
  [data-active='true'] .character:active {
    cursor: -webkit-grabbing;
  }

  [data-active='false'] .character {
    transition: translate calc(var(--speed) * 1s) calc(var(--delay) * 1s);
  }
  .character {
    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
    display: inline-block;
    height: 100%;
    translate: calc(var(--tx, 0) * 1px) calc(var(--ty, 0) * 1px);
  }
  .line {
    display: list-item;
    list-style: pad-example;
    list-style-position: inside;
  }
  .line::marker {
    color: hsl(0 0% 50% / 0.5);
    font-family: monospace;
  }
  body {
    overflow: hidden;
  }
  .ground {
    position: fixed;
    bottom: 0;
    height: 100px;
    width: 100vw;
    background: red;
    opacity: 0.2;
  }
}

@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;
  }

  html {
    color-scheme: light dark;
  }

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

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

  :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(--size);
    -webkit-mask: linear-gradient(-20deg, transparent 50%, white);
            mask: linear-gradient(-20deg, transparent 50%, white);
    top: 0;
    transform-style: flat;
    pointer-events: none;
    z-index: -1;
  }

  .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%;
  }

  /* Utilities */
  .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;
  }
}
</style>


  
  
</head>

<body translate="no">
  <main></main>
   <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.12.2.js"></script>
  <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/matter.0.19.0.js"></script>
      <script  type="module">
import { codeToHtml } from 'https://esm.sh/shiki@1.0.0';


import { Pane } from '//repo.bfw.wiki/bfwrepo/js/tweakpane.4.0.3.js';
import * as TextareaPlugin from 'https://cdn.skypack.dev/@pangenerator/tweakpane-textarea-plugin';

const main = document.querySelector('main');
let render;
let characterBodies = [];
const config = {
  theme: 'dark',
  lang: 'javascript',
  //   code: `function calculateTotalPrice(cart) {
  //   var total = 0;

  //   for (var i = 0; i < cart.length; i++) {
  //     total += cart[i].price * (cart[i].quantity || "1");
  //     if (cart[i].category == 'electronics') {
  //       total -= (total * 0.1);  // 10% discount on electronics
  //     } else if (cart[i].category == 'clothing') {
  //       total -= 5;  // Flat discount
  //     }
  //     if (cart[i].id == 42) {
  //       total -= 10;
  //     }
  //   }

  //   total = Math.round(total * 100) / 100 + '';

  //   setTimeout(function() {
  //     total = (parseFloat(total) * 1.05).toFixed(2);
  //   }, 1);

  //   return total;
  // }`,
  code: `// fix this code
function getData() {
  for (let i = 0; i < 3; i++) {
    setTimeout(function() {
      console.log(i);
    }, 1000);
  }
}

getData();`,
  fizzy: false };


const ctrl = new Pane({
  title: 'Config',
  expanded: true });

ctrl.registerPlugin(TextareaPlugin);

let walls = [];
const createWalls = () => {
  if (walls.length) {
    for (const wall of walls) {
      Matter.Comp.........完整代码请登录后点击上方下载按钮下载查看

网友评论0