10
CSS 3 Transitions
Its been sometime since CSS3 has been introduced, bringing some interesting new presentational techniques along with it. Today, we’ll review the basics of using CSS3 transitions to add an extra layer of polish.
Let’s create a simple example of animating a pop out sign.
First Create a Div with images
<div id="signpost"> <img id="post" src="post.png"> <img id="sign" src="sign.png"> </div> |
Create the bounding box for the signpost, and give it a relative positioning context to ensure that we can position items absolutely within it.
#signpost{ width:60px; height:196px; position:relative; } |
Next, the post is positioned with a z-index of two, to place it on top of the sign.
#post{ width:79px; height:196px; z-index:2; position:relative; } |
Now we place sign underneath the Post and rotate it with our CSS3 transform property
#sign{ height:46px; width:80px; position:absolute; top:10; left:60; -webkit-transform-origin:0 0; -moz-transform-origin:0 0; -webkit-transform: rotate(86deg); -moz-transform: rotate(86deg); z-index:1; -webkit-transition:-webkit-transform 0.5s ease-in-out; } |
The sign is rotated using transform: rotate(86deg), and is positioned under the post. To ensure that the sign rotates around the proper point, we must change the transform origin to the top left corner: 0, 0.
We set the transition to change the transform property over 0.5s with an ease-in-out profile, and on hover, we rotate the sign back to its original orientation.
#signpost:hover #sign{ -webkit-transform:rotate(0deg); -moz-transform:rotate(0deg); } |
Reference: http://net.tutsplus.com
Sign up for our mailing list.
Categories
Recent Comments
- Shankar on 8 Best WordPress Video Plugins
- Shankar on 5 Cool Video plugins for WordPress
- irshad on Creating Secure Login in PHP
- jaliya on How to refresh DIV using jquery
- anika on How to insert twitter updates in your webpage






