Spaceship

This demonstrates the use of CSS to create an indefinite orbit animation.

by Adam Howard

HTML

<div id="stars"></div>
<img id="asteroid" src="http://goo.gl/lvLFI3">
<div id="rocket">
<img src="http://goo.gl/4C9VUJ" id="rocketBody">
</div>

CSS

body{
  background: url("http://goo.gl/AOYSM9");  
  background-repeat: repeat;
  overflow: hidden;
  animation: spaceTravel 25s linear infinite;
  margin: 0;
}

#stars{
  margin: 0;
  width: 100%;
  height: 100%;
  background: url("http://goo.gl/OFj2bC");
  position: absolute;
  z-index: 3;
  animation: spaceTravel 6s linear infinite;
  background-size: 30000px;
}

#asteroid {
  position: absolute;
  z-index: 2;
  left: 190px;
  top: 70px;
  width: 220px;
  animation: rotateAsteroid 25s linear infinite;
}

#rocket {
  position: absolute;
  z-index: 1;
  left: 265px;
  top: 150px;
  animation: orbit 4.5s linear infinite;
}

#rocketBody {
  width: 65px;
  animation: rotateShip 4.5s linear infinite;
}

@keyframes rotateAsteroid {
    from {transform: rotateZ(0deg);}
    to {transform: rotateZ(-360deg);}
}

@keyframes rotateShip {
    from {transform: rotateZ(180deg);}
    to {transform: rotateZ(540deg);}
}

@keyframes orbit {
    from {transform: rotate(0deg) translateX(120px) rotate(0deg); }
    to   {transform: rotate(360deg) translateX(120px) rotate(-360deg); }
}

@keyframes spaceTravel {
    from {background-position: 0px 0px;}
    to {background-position: -1024px 1024px;}
  
}