<div class="container">
<p>Hover over the container to see the element animate.</p>
<div class="element element-1">
</div>
<p>Using CSS Transitions:</p>
<div class="element element-2">
</div>
</div>
* {
box-sizing: border-box;
}
body {
background-color: #F5F5F5;
color: #555;
font-size: 1.1em;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.container {
margin: 100px auto;
min-width: 300px;
max-width: 500px;
padding: 1em;
box-sizing: border-box;
background-color: white;
border: 1px solid #aaa;
}
.element {
padding: 20px;
width: 30px;
height: 30px;
background-color: #0073b9;
position: relative;
top: 0;
left: 0;
}
.container:hover .element-1 {
-webkit-animation: jump 3s linear both;
animation: jump 3s linear both;
}
.element-2 {
-webkit-transition: left 2s linear;
transition: left 2s linear;
}
.container:hover .element-2 {
left: 200px;
}
@-webkit-keyframes jump {
0% {
left: 0;
top: 0;
}
50% {
left: 100px;
top: -100px;
}
100% {
left: 200px;
top: 0;
}
}
@keyframes jump {
0% {
left: 0;
top: 0;
}
50% {
left: 100px;
top: -100px;
}
100% {
left: 200px;
top: 0;
}
}