Monday 26 December 2011

css3 Transform - The matrix() Method

The matrix() Method:

The matrix() method combines all of the 2D transform methods into one.
The matrix method take six parameters, containing mathematic functions, which allows you to: rotate, scale, move (translate), and skew elements.

Syntax:    How to rotate a div element 30 degrees, using the matrix method

 div
 {
 transform:matrix(0.866,0.5,-0.5,0.866,0,0);
 -ms-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* IE 9 */
 -moz-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Firefox */
 -webkit-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Safari and Chrome */
 -o-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Opera */
 }

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> matrix Method </title>
 <style type="text/css">
 body{margin:0;padding:50px; background:#eee; color:#fff }
 div
 {
 width:100px;
 height:75px;
 background-color: #660066;
 border:1px solid black;
 }
 div#div2
 {
 transform:matrix(0.866,0.5,-0.5,0.866,0,0);
 -ms-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* IE 9 */
 -moz-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Firefox */
 -webkit-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Safari and Chrome */
 -o-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Opera */
 }
 </style>
 </head>
 <body>
 <div>Hello. This is a DIV element.</div>
 <div id="div2">World. This is a DIV element.</div>
 </body>
 </html>

Result: 

No comments:

Post a Comment