High performing animations have become increasingly important, as interactive projects get more aggressive and smart devices have burst into the scene. Widely used JQuery has not been able to handle the onslaught, because it simply wasn’t designed for it. The most widely-acclaimed solution is CSS Animations (and Transitions). With CSS3, we can create animations which can replace flash animations, animated images, and JavaScript in existing web pages.
The @Key frames rule is where the animation is created. Specify a CSS style inside the @Key frames rule and the animation will gradually change from the current style to the new style.
1. Create a CSS file with code as shown below
2. The class name for the textbox is, ‘sample’
3. Add the CSS in the Application
4. Add a text box to the center of the canvas(outline)
5. Include the class name ‘sample’ in the textbox
6. Execute to view the transition and animation
CSS Animation Code
.sample {
width: 100px;
height: 100px;
background: red;
position: relative;
/* Chrome, Safari, Opera */
-webkit-animation-name: myfirst;
-webkit-animation-duration: 5s;
-webkit-animation-timing-function: linear;
-webkit-animation-delay: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-play-state: running;
/* Standard syntax */
animation-name: myfirst;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state: running;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes myfirst {
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
/* Standard syntax */
@keyframes myfirst {
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |