Showing posts with label Change the background through animation property. Show all posts
Showing posts with label Change the background through animation property. Show all posts

Tuesday, 27 December 2011

Change the background through animation property

Change the background color when the animation is 25%, 50%, and again   when the animation is 100% complete:@keyframes myfirst 

 Syntax : 
 {
 0%   {background: red;}
 25%  {background: yellow;}
 50%  {background: blue;}
 100% {background: green;}
 }

 @-moz-keyframes myfirst /* Firefox */
 {
 0%   {background: red;}
 25%  {background: yellow;}
 50%  {background: blue;}
 100% {background: green;}
 }

 @-webkit-keyframes myfirst /* Safari and Chrome */
 {
 0%   {background: red;}
 25%  {background: yellow;}
 50%  {background: blue;}
 100% {background: green;}

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>animation-rotation </title>
 <style type="text/css">
 body{margin:0;padding:50px; background:#eee;color:#fff }
 div
 {
 width:200px;
 height:200px;
 background: #663366;
 position:relative;
 animation:myfirst 5s;
 -moz-animation:myfirst 5s; /* Firefox */
 -webkit-animation:myfirst 5s; /* Safari and Chrome */
 }
 {
 0%   {background: red;}
 25%  {background: yellow;}
 50%  {background: blue;}
 100% {background: green;}
 }

 @-moz-keyframes myfirst /* Firefox */
 {
 0%   {background: red;}
 25%  {background: yellow;}
 50%  {background: blue;}
 100% {background: green;}
 }

 @-webkit-keyframes myfirst /* Safari and Chrome */
 {
 0%   {background: red;}
 25%  {background: yellow;}
 50%  {background: blue;}
 100% {background: green;}
 </style>
 </head>
 <body>
 <div>Hello World.
 <p> The div element changes the background effect.</p>
 </div>
 </body>
 </html>