#100DAYSOFCODE Day64

#100DAYSOFCODE Day64

2B01094C-8142-4EB4-8BE8-46740BEAFC07_4_5005_c.jpeg

This is an interesting question I saw when applying for a job. When the car skidding stops, the car speed will gradually decrease from fast to 0 speed, so I will use animation-timing-function like "ease-out" to change the car move speed. I use the "cubic-bezier" to custom speed settings.

Also, I set the car body and lights will up and down(translateY) a little bit, and the car wheels will rotate themselves 360 deg.

maybe if wheels can stop or slow rotating when the car skidding stops, it would be better.

CSS:
#truck {
  width: 100%;
  animation: car 1.5s ease-out infinite;
  animation-timing-function: cubic-bezier(0, 0.3, 0.4, 1);;
}
@keyframes car {
  from {
    transform: translateX(50%);
  }
  to {
    transform: translateX(-8%);
  }
}

#lights {
  animation: light 1s ease-in-out infinite alternate;
}
#car-body {
  animation: light 1s ease-in-out infinite alternate;
}
@keyframes light {
  from {
    transform: translateY(0%);
  }
  to {
    transform: translateY(1%);
  }
}

#right-wheel {
  animation: wheel 1s infinite linear;
  transform-origin: center;
  transform-box: fill-box;
}
@keyframes wheel {
  from {
    transform: rotateZ(0deg);
  }
  to {
    transform: rotateZ(360deg);
  }
}