Pure CSS element animation

Asked

Viewed 137 times

1

As I can perform a scheme in pure CSS with a ball simulating the traffic, the ball would be circulating in the lines, see a scheme

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

It got a little strange but the demonstration of the idea, the ball, represented by *, would walk the lines going from the SERVER->YOU->ME endlessly, just to demonstrate

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

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 the positioning of the elements I used position:absolute to position them according to their div father.

* {
  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>

  • I thank you very much for your time spent with my problem!!!

  • Thank you for being able to help and learning new things from it.

3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.