div+css实现胖墩墩的小兔子动画效果代码

代码语言:html

所属分类:动画

代码描述:div+css实现胖墩墩的小兔子动画效果代码

代码标签: div css 胖墩墩 小兔子 动画

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


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

<head>

  <meta charset="UTF-8">
  
<link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png" />
<meta name="apple-mobile-web-app-title" content="CodePen">

<link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />

<link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg" color="#111" />


  
  <title>CodePen - CSS Rabbit Trap</title>
  
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
  
<style>
* {
  box-sizing: border-box;
}

:root {
  font-size: 10px;
}

body {
  font-family: "Poppins", sans-serif;
  min-height: 100vh;
  background: #210c05;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.reference {
  z-index: 1;
  position: fixed;
  bottom: 1em;
  left: 0;
  right: 0;
  text-align: center;
  color: #db8251;
  font-size: 24px;
  text-decoration: none;
}

.window {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(1.75em);
  width: 87.5em;
  height: 67.5em;
  overflow: hidden;
  background-color: #e27450;
  box-shadow: 0 0 1em 0.25em #e27450;
}
.window .bottom {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 5.425em;
  background: #000;
  background: linear-gradient(#d16a47, #0000);
  clip-path: polygon(4.3% 0%, 95.8% 0%, 100% 100%, 0% 100%);
}
.window .top {
  position: absolute;
  top: 0;
  width: 100%;
  height: 2.05em;
  background: #000;
  background: linear-gradient(0deg, rgba(209, 106, 71, 0.75), #0000);
  clip-path: polygon(0% 0%, 100% 0%, 95.8% 100%, 4.3% 100%);
}

.scene {
  position: relative;
  width: 80em;
  height: 60em;
  overflow: hidden;
  background: linear-gradient(#e9825b, #e2734e);
  box-shadow: 0 0 2em 0.375em #0002;
}

.floor {
  width: 100%;
  height: 100%;
}
.floor .rabbit-shadow {
  position: absolute;
  bottom: 0;
  right: 0;
  transform: translate(-13.5em, -25.7em);
  width: 32.1em;
  height: 12.3em;
  background-image: radial-gradient(ellipse at 60%, rgba(204, 73, 40, 0.75) 10%, rgba(204, 73, 40, 0) 30%), radial-gradient(ellipse, #d75333 30%, #d75333 40%, rgba(217, 94, 63, 0.75) 50%, #0000 70%);
}
.floor .carrot-shadow {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(22em, 40em);
  width: 12em;
  height: 4.25em;
  background-image: linear-gradient(-90deg, #e47753 20%, #0000), radial-gradient(ellipse at right, #bb301b 45%, #cf5830 48%, #cf5830 56%, rgba(222, 106, 74, 0.75) 66%, #0000 70%), radial-gradient(circle at bottom right, rgba(207, 88, 48, 0.8) 48%, #0000 55%);
  filter: blur(0.25em);
}

.rabbit {
  position: absolute;
  bottom: 0;
  left: 0;
  transform: translate(44.7em, -27.6em);
  width: 21.7em;
  height: 19em;
  border-radius: 85% 85% 90% 90%/100% 100% 75% 75%;
  background-color: #e7e7de;
  background-image: radial-gradient(circle at bottom left, #d7957f, #fff0 50%);
  box-shadow: 0.1em -0.1em 0.25em 0 #3331, -0.1em 0.5em 0.25em -0.25em #bb4325, inset -0.15em 0.1em 0.2em 0 #fff6;
}
.rabbit .eye {
  position: absolute;
  width: 7%;
  height: 14%;
  background-color: #322923;
  box-shadow: inset 0 -0.5em 0.5em 0 #62170f, inset -0.075em 0.1em 0.1em 0 #b9b5ac, 0 0 0.25em 0 #0006;
}
.rabbit .eye.l {
  border-radius: 90% 90% 90% 100%/90% 90% 100% 100%;
  left: 9.2%;
  top: 46%;
  transform: translateY(-50%) rotate(10deg);
  background-image: radial-gradient(circle at 0% 60%, #0000 77%, #ffa);
}
.rabbit .eye.r {
  border-radius: 90% 90% 90% 90%/90% 90% 90% 90%;
  left: 21.2%;
  top: 53.4%;
  transform: translateY(-50%) rotate(10deg);
  background-image: radial-gradient(circle at -25% 90%, #0000 77%, #fff);
}
.rabbit .ear {
  position: absolute;
  background-color: #e6e6e6;
  border-radius: 70% 50% 100% 20%/75% 20% 100% 20%;
}
.rabbit .ear.l {
  --width: 3.3em;
  --height: 9em;
  position: absolute;
  width: var(--width);
  height: var(--height);
  left: 6.7em;
  top: calc(6.3em - var(--height));
  transform: rotate(35deg);
  background-image: radial-gradient(circle at bottom left, #cca592aa, #fff0 70%);
  box-shadow: 0 0.1em 0.25em 0 #0004, inset -0.25em 0 0.5em 0 #0001;
}
.rabbit .ear.r {
  --width: 3.3em;
  --height: 8.5em;
  position: absolute;
  width: var(--width);
  height: var(--height);
  left: 10.25em;
  top: calc(8.3em - var(--height));
  transform: rotate(45deg);
  border-radius: 100% 60% 100% 40%/60% 20% 100% 100%;
  background-image: radial-gradient(circle at bottom left, #cca592aa, #fff0 35%);
  box-shadow: 0 0.1em 0.25em 0 #0004, inset -0.5em 0 0.75em 0 #0002;
}

.carrot {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(26.8em, 38.9em);
  width: 4.5em;
  height: 4em;
}
.carrot .orange {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 100% 100% 100% 100%/80% 80% 60% 60%;
  background-color: #db8251;
  background-image: radial-gradient(circle at bottom right, #ecae8d 30%, #fff0 60%), radial-gradient(ellipse at top, #d5a57c 25%, #dc8756 35%, #dd8a5a 40%);
  background-size: 100%, 250% 100%;
  background-position: 100%, center;
  background-repeat: no-repeat;
  box-shadow: -0.1em 0.1em 0.25em 0 #0001, inset 2.5em 0 1em -0.5em #0002;
}
.carrot .orange:before {
  content: "";
  position: absolute;
  top: -5%;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-image: radial-gradient(circle at top, #0000 60%, rgba(213, 97, 48, 0.75) 70%, rgba(213, 97, 48, 0.75) 70%, #0000 85%);
  transform: rotateZ(15deg) rotateX(40deg);
  filter: blur(0.15em);
}
.carrot .orange:after {
  content: "";
  position: absolute;
  top: 0.5em;
  left: 0;
  width: 85%;
  height: 100%;
  border-radius: 50%;
  background-image: radial-gradient(circle at top, #0000 60%, rgba(213, 97, 48, 0.75) 70%, rgba(213, 97, 48, 0.75) 70%, #0000 85%);
  transform: rotateZ(20deg) rotateX(40deg);
  filter: blur(0.15em);
}
.carrot .green {
  position: absolute;
  width: 0;
  height: 0;
  left: 2em;
}
.carrot .green .stem {
  position: absolute;
  width: 0.9em;
  height: 0.7em;
  transform: translateX(-50%);
  border-radius: 58% 42% 63% 37%/87% 0% 100% 13%;
  background-color: #455313;
  box-shadow: inset 0.1em 0 0 0 #747a1a;
  filter: blur(0.035em);
}
.carrot .green .leaf {
  position: absolute;
  background-color: #9ed586;
}
.carrot .green .leaf.left {
  width: 2.1em;
  height: 1em;
  transform: translate(-100%, -65%);
  border-radius: 56% 44% 79% 21%/61% 55% 45% 39%;
  box-shadow: inset 0.05em -0.05em 0 0 #5b892a, inset 0.25em -0.2em 0.25em 0 #6ab33d;
}
.carrot .green .leaf.middle {
  width: 1.3em;
  height: 2em;
  transform: translate(-50%, -100%);
  border-radius: 52% 48% 50% 50%/20% 20% 80% 80%;
  box-shadow: inset 0.05em -0.1em 0.1em 0 #5b892a, inset 0.25em -1.2em 0.25em -0.4em #6ab33d;
}
.carrot .green .leaf.right {
  width: 2.6em;
  height: 1.6em;
  transform: translate(0, -45%);
  border-radius: 56% 44% 38% 62%/45% 62% 38% 55%;
  box-shadow: inset 0 -0.05em 0 0 #5b892a, inset 0.25em -0.2em 0.25em 0 #6ab33d;
}

/*
Animation - Rabbit
*/
.rabbit {
  animation: rabbit 3s infinite;
}

@keyframes rabbit {
  1% {
    transform: translate(44.7em, -27.6em);
    width: 21.7em;
    height: 19em;
  }
  2% {
    transform: translate(44.7em, -27.6em);
    width: 21.7em;
    height: 18.3em;
  }
  3% {
    transform: translate(44.2em, -32em);
    width: 21.7em;
    height: 18.8em;
  }
  4% {
    transform: translate(42.7em, -34.6em);
    width: 21.8em;
    height: 19.4em;
  }
  5% {
    transform: translate(40.7em, -35.3em);
    width: 21.7em;
    height: 19.6em;
  }
  6% {
    transform: translate(38.2em, -34.5em);
    width: 21.8em;
    height: 19.7em;
  }
  7% {
    transform: translate(35.6em, -32em);
    width: 21.8em;
    height: 19.6em;
  }
  8% {
    transform: translate(33.2em, -28.2em);
    width: 21.8em;
    height: 19.4em;
  }
  9% {
    transform: translate(31.2em, -23.9em);
    width: 21.6em;
    height: 19.3em;
  }
  10% {
    transform: translate(29.7em, -19em);
    width: 21.7em;
    height: 16.8em;
  }
  11% {
    transform: translate(29.2em, -18.6em);
    width: 21.7em;
    height: 17.8em;
  }
  12% {
    transform: translate(29.2em, -18.6em);
    width: 21.7em;
    height: 18.9em;
  }
  13% {
    transform: translate(29.2em, -18.6em);
    width: 21.7em;
    height: 18.8em;
  }
  14% {
    transform: translate(29.2em, -18.6em);
    width: 21.7em;
    height: 18.6em;
  }
  15%, 16%, 17%, 18% {
    transform: translate(29.2em, -18.6em);
    width: 21.7em;
    height: 18.4em;
  }
  19% {
    transform: translate(30.3em, -19.4em);
    width: 19.8em;
    height: 18.4em;
  }
  20% {
    transform: translate(31.4em, -20.3em);
    width: 18em;
    height: 18.2em;
  }
  21% {
    transform: translate(31.3em, -20.4em);
    width: 18.1em;
    height: 18em;
  }
  22% {
    transform: translate(31.3em, -20.2em);
    width: 18.2em;
    height: 18.1em;
  }
  23% {
    transform: translate(31em, -20.1em);
    width: 18.6em;
    height: 18em;
  }
  24% {
    transform: translate(30.8em, -19.9em);
    width: 19em;
    height: 18.1em;
  }
  25%, 26% {
    transform: translate(30.8em, -19.9em);
    width: 19em;
    height: 18em;
  }
  27% {
    transform: translate(29.2em, -18.4em);
    width: 22.3em;
    height: 20.9em;
  }
  28% {
    transform: translate(24.5em, -13.3em);
    width: 32.3em;
    height: 30.4em;
  }
  29% {
    transform: translate(16.6em, -5.4em);
    width: 49em;
    height: 45.6em;
  }
  30% {
    /*
    Repeat initial absolute position to prevent shifting to
    new absolute posiiton in 31%.
    */
    bottom: 0;
    left: 0;
    transform: translate(7em, 0em);
    width: 69.8em;
    height: 65em;
  }
  31% {
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    width: 99.4em;
    height: 92.7em;
  }
  32% {
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    width: 108.5em;
    height: 95em;
  }
  33% {
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    width: 113.9em;
    height: 99.6em;
  }
  34% {
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    width: 117.2em;
    height: 102.6em;
  }
  35% {
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    width: 119.4em;
    height: 104.5em;
  }
  /*
  Rabbit is not visible from 36 -> 79
  Moving it.........完整代码请登录后点击上方下载按钮下载查看

网友评论0