gsap+Draggable实现拖拽响应式窗口自适应可爱小蛇效果代码

代码语言:html

所属分类:响应式

代码描述:gsap+Draggable实现拖拽响应式窗口自适应可爱小蛇效果代码

代码标签: gsap Draggable 拖拽 响应式 窗口 自适应 可爱 小蛇

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

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

<style>
    @import url('https://unpkg.com/normalize.css') layer(normalize);

@layer normalize, base, demo;

@layer demo {
  html {
    color-scheme: light only;
  }
  .dialog {
    overflow: hidden;
    resize: horizontal;
    display: grid;
    place-items: center;
    /* min-width: 200px;
    max-width: calc(600px + 0.5rem); */
    min-width: 200px;
    width: clamp(200px, 600px, 80vw - 2rem);
    max-width: calc(100vw - 2rem);
    position: absolute;
    padding: 0;
    border-width: 4px;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 10px 20px -10px hsl(0 0% 0% / 0.5);
  }
  .dialog:active .dialog__arrow {
    display: none;
  }
  .dialog__arrow {
    height: 30px;
    width: 20px;
    background: #262626;
    position: absolute;
    bottom: 15px;
    right: 8px;
    transform-origin: 50% 100%;
    transform: rotate(-45deg);
    -webkit-clip-path: polygon(
      50% 100%,
      100% 60%,
      60% 60%,
      65% 0,
      35% 0,
      35% 60%,
      0 60%
    );
            clip-path: polygon(
      50% 100%,
      100% 60%,
      60% 60%,
      65% 0,
      35% 0,
      35% 60%,
      0 60%
    );
    z-index: 999;
    -webkit-animation: bounce 0.5s infinite linear;
            animation: bounce 0.5s infinite linear;
  }
  .dialog__header {
    height: 44px;
    background: color-mix(in lch, canvasText, canvas 25%);
    border-bottom: 4px solid #000;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 1rem;
    gap: 0.5rem;
    width: 100%;
  }
  dialog svg {
    width: 340px;
    max-width: 340px;
    aspect-ratio: 1;
  }
  .dialog__control {
    height: 12px;
    background: var(--bg, #f00);
    aspect-ratio: 1;
    border-radius: 50%;
  }
  .dialog__control--exit {
    --bg: #f2330d;
  }
  .dialog__control--minimize {
    --bg: #fa0;
  }
  .dialog__control--maximize {
    --bg: #19e619;
  }
  @-webkit-keyframes bounce {
    0,
    100% {
      transform: rotate(-45deg) translate(0, 0);
    }
    50% {
      transform: rotate(-45deg) translate(0, -15%);
    }
  }
  @keyframes bounce {
    0,
    100% {
      transform: rotate(-45deg) translate(0, 0);
    }
    50% {
      transform: rotate(-45deg) translate(0, -15%);
    }
  }
}

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

  body {
    display: grid;
    background: color-mix(in lch, canvas, canvasText 5%);
    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;
  }

  

  /* 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>

<dialog class="dialog" open="open">
      <div class="dialog__arrow"></div>
      <div class="dialog__header">
        <div class="dialog__control dialog__control--exit"></div>
        <div class="dialog__control dialog__control--minimize"></div>
        <div class="dialog__control dialog__control--maximize"></div>
      </div>
      <svg
        class="snek"
        viewbox="0 0 500 500"
        fill="none"
        xmlns="http://www.w3.org/2000/svg"
      >
        <marker
          id="tail"
          viewbox="0 0 36 20"
          refx="35"
          refy="10"
          markerunits="strokeWidth"
          orient=".........完整代码请登录后点击上方下载按钮下载查看

网友评论0