纯css实现一个老鼠转轮子动画效果

纯css实现一个老鼠转轮子动画效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
:root {
  --wheel-color: #01827F;
  --hamster-color: #F4B874;
}

body{
  background: lightgray;
}

.box-canvas{
  position: relative;
  margin: auto;
  display: block;
  margin-top: 8%;
  margin-bottom: 8%;
  width: 170px;
  height:200px;
}

.wheel-leg {
  width: 10px;
  height: 30px;
  background: #80CBC4;
  position: absolute;
  
  bottom: 20px;
  
}

.wheel-leg.left {
  left: 15px;
  -webkit-transform: rotate(25deg);
          transform: rotate(25deg);
}

.wheel-leg.right {
  right: 15px;
  -webkit-transform: rotate(-25deg);
          transform: rotate(-25deg);
}

.wheel {
  position: absolute;
  width: 150px;
  height: 150px;
  border: 10px solid var(--wheel-color);
  border-radius: 50%;
  background: conic-gradient(
    var(--wheel-color),
    var(--wheel-color) 5deg,
    transparent 5deg,
    transparent 60deg,
    var(--wheel-color) 60deg,
    var(--wheel-color) 65deg,
    transparent 65deg,
    transparent 120deg,
    var(--wheel-color) 120deg,
    var(--wheel-color) 125deg,
    transparent 125deg,
    transparent 180deg,
    var(--wheel-color) 180deg,
    var(--wheel-color) 185deg,
    transparent 185deg,
    transparent 240deg,
    var(--wheel-color) 240deg,
    var(--wheel-color) 245deg,
    transparent 245deg,
    transparent 300deg,
    var(--wheel-color) 300deg,
    var(--wheel-color) 305deg,
    transparent 305deg
  );
  -webkit-animation: spinWheel 1s infinite linear;
          animation: spinWheel 1s infinite linear;
}

@-webkit-keyframes spinWheel {
  0% {
    -webkit-transform: none;
            transform: none;
  }
  
  100% {
    -webkit-transform: rotate(-360deg);
            transform: rotate(-360deg);
  }
}

@keyframes spinWheel {
  0% {
    -webkit-transform: none;
            transform: none;
  }
  
  100% {
    -webkit-transform: rotate(-360deg);
            transform: rotate(-360deg);
  }
}

.wheel::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #80CBC4;
}

.wheel::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  width: 170px;
  height: 170px;
  border: 5px solid #80CBC4;
  border-radius: 50%;
}

.hamster {
  position: absolute;
  top: 102px;
  left: 50%;
  -webkit-transform: translateX(-50%);
          transform: translateX(-50%);
  width: 75px;
  height: 50px;
}

.body {
  width: 75px;
  height: 40px;
  position: absolute;
  bottom: 0;
  background: var(--hamster-color);
  -webkit-transform: rotate(10deg);
          transform: rotate(10deg);
  border-radius: 50% / 60% 60% 40% 40%;
  overflow: hidden;
}

.body::before {
  content: '';
  position: absolute;
  left: 50%;
  -webkit-transform: translateX(-50%);
          transform: translateX(-50%);
  width: 50px;
  height: 25px;
  background: #F2CEA4;
  bottom: -12px;
  border-radius: 50%;
}

.ear {
  position: absolute;
  left: 13px;
  top: 3px;
  width: 15px;
  height: 15px;
  background: var(--hamster-color);
  border-radius: 50%;
  border-right: 2px solid #E58627;
  -webkit-transform: rotate(10deg);
          transform: rotate(10deg);
}

.tail {
  position: absolute;
  right: -2px;
  top: 25px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--hamster-color);
}

.eye {
  position: absolute;
  left: 8px;
  top: 13px;
  width: 5px;
  height: 5px;
  background: black;
  border-radius: 50%;
}

.nose {
  position: absolute;
  left: 0px;
  top: 18px;
  width: 5px;
  height: 5px;
  background: #F78F9F;
  border-radius: 40%;
}

.nose::after {
  content: '';
  position: absolute;
  top: 5px;
  left: 1px;
  width: 8px;
  height: 5px;
  border-radius: 50%;
  box-shadow: 0 1px 0 black;
}

.leg {
  position: absolute;
  background: var(--hamster-color);
  width: 10px;
  height: 15px;
  border-radius: 30% 50% 30% 30%;
 
  box-shadow: 1px -1px 0 #E58627;
}

.leg.front {
  bottom: -7px;
  left: 15px;
  -webkit-transform: rotate(45deg);
          transform: rotate(45deg);
  -webkit-transform-origin: top right;
          transform-origin: top right;
  -webkit-animation: moveFrontLeg 0.1s infinite linear;
          animation: moveFrontLeg 0.1s infinite linear;
  animation-direction: alternate-reverse;
}

.leg.back {
  right: 15px;
  bottom: -6px;
  -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
  -webkit-transform-origin: top left;
          transform-origin: top left;
  -webkit-animation: moveBackLeg 0.1s infinite linear;
          animation: moveBackLeg 0.1s infinite linear;
  animation-direction: alternate-reverse;
}

@-webkit-keyframes moveFrontLeg {
  0% {
    -webkit-transform: rotate(65deg);
            transform: rotate(65deg);
  }
  
  100% {
    -webkit-transform: rotate(20deg);
            transform: rotate(20deg);
  }
}

@keyframes moveFrontLeg {
  0% {
    -webkit-transform: rotate(65deg);
            transform: rotate(65deg);
  }
  
  100% {
    -webkit-transform: rotate(20deg);
            transform: rotate(20deg);
  }
}


@-webkit-keyframes moveBackLeg {
  0% {
    -webkit-transform: rotate(25deg);
            transform: rotate(25deg);
  }
  
  100% {
    -webkit-transform: rotate(-65deg);
            transform: rotate(-65deg);
  }
}


@keyframes moveBackLeg {
  0% {
    -webkit-transform: rotate(25deg);
            transform: rotate(25deg);
  }
  
  100% {
    -webkit-transform: rotate(-65deg);
            transform: rotate(-65deg);
  }
}
</style>

</head>

<body>
<div class="box-canvas">
<div class="wheel-leg left"></div>
<div class="wheel-leg right"></div>
<div class="wheel">
</div>
<div class="hamster">
<div class="body">
<div class="eye"></div>
<div class="nose"></div>
</div>
<div class="ear"></div>
<div class="tail"></div>
<div class="leg front"></div>
<div class="leg back"></div>
</div>
</div>
</body>

</html>

网友评论0