element animation in pure CSS

1

How can I make a pure CSS layout with a ball simulating traffic, the ball would be circling the lines, see a diagram

SERVER --------> YOU
/\                |
|                 |
|                 *
|____  ME <_______|

It was kind of strange, but it's a demonstration of the idea, the ball, represented by * , would be walking on the lines going from SERVER-> YOU-> ME infinitely, just to demonstrate

I thought of a div with border and position the 3 elements with float but it would be gambiarra .. How to do it?

    
asked by anonymous 31.08.2015 / 03:13

2 answers

6

In the example below I used @keyframe and animation of CSS3 to modify the position of the circle as the animation progresses. For positioning the elements I used position:absolute to position them according to their div parent.

* {
  margin: 0;
  padding: 0;
}
#box {
  width: 150px;
  height: 100px;
  border: 2px solid #3df;
  position: absolute;
  top: 20%;
  left: 40%;
}
span {
  display: block;
  position: absolute;
  background: #fff;
  z-index: 10;
}
#server {
  top: -10px;
  left: -10px;
}
#you {
  top: -10px;
  right: -10px;
}
#me {
  bottom: -10px;
  left: 40%;
}
#bl {
  width: 10px;
  height: 10px;
  background: #000;
  border-radius: 100%;
  border: 2px solid #fff;
  top: -7%;
  left: -5.5%;
  z-index: 11;
  -webkit-animation: ball 4s linear infinite;
  animation: ball 4s linear infinite;
}
@-webkit-keyframes ball {
  0% {
    top: -7%;
    left: -5.5%;
  }
  25% {
    top: -7%;
    left: 96%;
  }
  50% {
    top: 94%;
    left: 96%;
  }
  75% {
    top: 94%;
    left: -5.5%;
  }
}
@keyframes ball {
  0% {
    top: -7%;
    left: -5.5%;
  }
  25% {
    top: -7%;
    left: 96%;
  }
  50% {
    top: 94%;
    left: 96%;
  }
  75% {
    top: 94%;
    left: -5.5%;
  }
}
<div id="box">
  <span id="you">YOU</span>
  <span id="server">SERVER</span>
  <span id="me">ME</span>
  <span id="bl"></span>
</div>
    
09.09.2015 / 16:47
3

You can use the coordinates of the page to position the 'server', 'you' and 'me' elements and use the 'animation' property to move the ball. Like this:

link

and you can make the ball with CSS like this:

.ball{
    border-radius: 50%;
    display: inline-block;
    height: 20px;
    width: 20px;
    background-color: #000;
}
    
31.08.2015 / 14:12