css keyframe animation code example
Example 1: css keyframes animation
//css keyframes
#image{
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation: monFrame 5s linear 2s infinite alternate;
}
@keyframes monFrame {
0% {left:0px; top:0px;}
25% {left:500px; top:0px;}
50% {left:500px; top:500px;}
75% {left:0px; top:500px;}
100% {left:0px; top:0px;}
}
Example 2: css keyframes
@keyframes mymove {
from {top: 0px;}
to {top: 200px;}
}
Example 3: animation css
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation: myfirst 5s linear 2s infinite alternate;
}
@keyframes myfirst {
0% {background-color:red; left:0px; top:0px;}
25% {background-color:yellow; left:200px; top:0px;}
50% {background-color:blue; left:200px; top:200px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div><p>you can add text in this box or anithing else like a pictrue</p></div>
</body>
</html>
Example 4: keyframe in css
@keyframes mymove {
0% {top: 0px;}
50% {top: 50px;}
75% {top: 40px;}
100%{top: 0px;}
}
Example 5: learn css animation
Read this helpful, short and straightforward article to learn CSS animation perfectly.
https://medium.com/@Cafe_Code/learn-css-animation-asap-as-simple-as-possible-374b7874d4dd
Example 6: webkit animation
@-webkit-keyframes pulse {
0% {
background-color: red;
opacity: 1.0;
-webkit-transform: scale(1.0) rotate(0deg);
}
33% {
background-color: blue;
opacity: 0.75;
-webkit-transform: scale(1.1) rotate(-5deg);
}
67% {
background-color: green;
opacity: 0.5;
-webkit-transform: scale(1.1) rotate(5deg);
}
100% {
background-color: red;
opacity: 1.0;
-webkit-transform: scale(1.0) rotate(0deg);
}
}
.pulsedbox {
-webkit-animation-name: pulse;
-webkit-animation-duration: 4s;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease-in-out;
}