CSS3 Transform Matrix
css3中的transform让我们操作变形变得很简单,诸如,translate–移动,scale–缩放,rotate–旋转,skew–斜切。这几个属性很方便,也很简单,但是其中matrix我们就不常使用了吧。-webkit-transform: matrix(1, 0, 0, 1, 100, 100)看到这样一句css,你也许很讨厌怎么一堆的数字,你也许斜视matrix–css也能搞出这货?这篇文章我们一起探讨一下transform中的matrix。
一、初识matrix
2d matrix提供6个参数啊a,b,c,d,d,e,f其基本写法如下:
回顾一下高中数学,或者线性代数,即可知道matrix计算方法。x和y是元素初始的坐标,x’ 和y’则是通过矩阵变换后得到新的坐标。通过中间的那个3×3的变换矩阵,对原先的坐标施加变换,就能得到新的坐标了。依据矩阵变换规则即可得到: x’=ax+cy+e
y’=bx+dy+f。
transform中translate,scale,rotate,skew背后实现原理也对应着matrix变化,下边依次解释:
变换矩阵公式可参考变换矩阵wiki(http://zh.wikipedia.org/zh-cn/%E5%8F%98%E6%8D%A2%E7%9F%A9%E9%98%B5)
二、移动translate
移动matrix参数为:matrix(1,0,0,1,Δx,Δy)(Δx,Δy分别对应x和y轴的增量)。由此公式可知:
-webkit-transform: translate(100px,100px);即对应着-webkit-transform: matrix(1, 0, 0, 1, 100, 100);
推算出: x’ = 1*x+0 * y+100 = x+100 , y’ = 0 * x+1 * y+100 = y+100。

三、缩放scale
缩放matrix参数为:matrix(kx*x,0,0,ky*y,0,0)(kx,和ky分别对应x和y轴缩放比率)。由此公式可知:
-webkit-transform: scale(1.5,1.5);及对应着 -webkit-transform: matrix(1.5, 0, 0, 1.5, 0, 0);
推算出: x’ = 1.5*x+0 * y+0 = 1.5 * x , y’ = 0 * x+1.5 * y+0 =1.5 * y。

四、旋转rotate
旋转matrix参数为:matrix(cosθ,sinθ,-sinθ,cosθ,0,0),由此可知
-webkit-transform: rotate(45deg);即对应着 -webkit-transform: matrix(0.53, 0.85, -0.85, 0.53, 0, 0);
(sin(45′)=0.85,cos(45′)=0.53)
推算: x’ = x*cos(45′)-y*sin(45′)+0 = x*cos(45′)-y*sin(45′),y’ = x*sin(45′)+y*cos(45′)+0 = x*sin(45′)+y*cos(45′)

五、斜切skew
斜切matrix参数为matrix(1,tan(θy),tan(θx),1,0,0),由此可知
-webkit-transform: skew(45deg);即对应着 -webkit-transform: matrix(1,0,1,1,0,0);
(tan(45′)=1)
推算出 x’ = x+y*tan( 45′ )+0 = x+y*tan( 45′ ), y’ = x*tan( 45′ )+y+0 = x*tan( 45′)+y

六、镜相对称
镜像对称没有相应的简化操作。终于有一个只能用matrix实现得了。。。
假设对称轴为y=kx直线,那么以这条直线对称的图形matrix为
matrix(2*ux^2-1,2*ux*uy,2*ux*uy,2*uy^2-1,0,0)
求解过程为:
假设(ux,uy)为直线方向的单位向量。也就是说,如果直线方程是y=kx,那么ux=1/sqrt(1+k^2),uy=k/sqrt(1+k^2),
推算出: x’ = (2*ux^2-1)*x+2*ux*uy*y
y’ = 2*ux*uy*x+(2*uy^2-1)*y。 
七、3d变换矩阵
3d矩阵即为透视投影,推算方法与2d矩阵相类似 
3d变换矩阵代码示例,matrix变为matrix3d
-webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) 
八、ie matrix滤镜
ie matrix滤镜仅能实现旋转和拉伸,具体写法为:
filter: progid:DXImageTransform.Microsoft.Matrix( enabled= bEnabled , SizingMethod= sMethod , FilterType= sType , Dx= fDx , Dy= fDy , M11= fM11 , M12= fM12 , M21= fM21 , M22= fM22 )
其中M11, M12, M21, M22分别对应2d矩阵中的a,c,b,d。
1’ 所以旋转实现即为:
M11=cos(roation),M12=-sin(roation),M21=sin(roation),M22=cos(roation)
对应此段代码ie7下截图为:
filter: progid:DXImageTransform.Microsoft.Matrix( enabled= bEnabled , SizingMethod=’auto expand’, FilterType= sType , M11= 0.53 , M12= -0.85 , M21= 0.85 , M22= 0.53 ) 
2‘ ie7缩放实现对应截图:
filter: progid:DXImageTransform.Microsoft.Matrix( enabled= bEnabled , SizingMethod=’auto expand’, FilterType= sType , M11=1.5 , M12= 0 , M21= 0 , M22=1.5 ) 
其他变换可以发挥想想啦。。。。
参考文章:
http://zh.wikipedia.org/zh-cn/%E5%8F%98%E6%8D%A2%E7%9F%A9%E9%98%B5
http://www.w3.org/TR/css3-2d-transforms/
http://dev.opera.com/articles/view/understanding-the-css-transforms-matrix/
http://msdn.microsoft.com/en-us/library/ms533014(v=vs.85).aspx
CSS3 Transform Matrix的更多相关文章
- css3 transform matrix矩阵的使用
Transform 执行顺序问题 — 后写先执行 matrix(a,b,c,d,e,f) 矩阵函数 •通过矩阵实现缩放 x轴缩放 a=x*a c=x*c e=x*e; y轴缩放 b= ...
- 【CSS3】 理解CSS3 transform中的Matrix(矩阵)
理解CSS3 transform中的Matrix(矩阵) by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu ...
- 理解CSS3 transform中的Matrix(矩阵)
一.哥,我被你吓住了 打架的时候会被块头大的吓住,学习的时候会被奇怪名字吓住(如“拉普拉斯不等式”).这与情感化设计本质一致:界面设计好会让人觉得这个软件好用! 所以,当看到上面“Matrix(矩阵) ...
- 理解CSS3 transform中的Matrix(矩阵)——张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=2427 一.哥,我被你 ...
- css3 transform中的matrix矩阵
CSS3中的矩阵CSS3中的矩阵指的是一个方法,书写为matrix()和matrix3d(),前者是元素2D平面的移动变换(transform),后者则是3D变换.2D变换矩阵为3*3, 如上面矩阵示 ...
- 矩阵matrix变换的用法(css3属性transform: matrix)
参数 2D矩阵的表示 matrix(a,b,c,d,e,f),其中6个参数在矩阵的分布: -- -- | a c e | | b d f | | 0 0 1 | -- -- 在CSS3中矩阵的原始值是 ...
- HTML 学习笔记 CSS3 (2D Matrix)
Matrix 矩阵 那么什么是矩阵呢? 矩阵可以理解为方阵,只不过 平时方阵里面站着人 矩阵中是数值: CSS3中的矩阵: css3中的矩阵指的是一个方法,书写为matrix() 和 matrix3d ...
- 制作变形、移位、扭曲等效果:《CSS3 transform》
今天开始我们一起来学习有关于CSS3制作动画的几个属性:变形(transform).转换(transition)和动画(animation)等更高级的CSS3技术.本文主要介绍的是这三个属性之中的第一 ...
- 【消灭代办】第2周 - 数组判断、开发工具、transform:matrix、Grid
2018.11.19代办一:[数组判断] 代办描述: 怎么判断一个数组是数组呢?其实这个也是一个常考的题目 关键考点: 1.js中对象类型判断的几种方法 2.数组的知识和灵活运用 解决方案s: 篇幅过 ...
随机推荐
- VB的判断语句和循环语句
判断语句 •If语句 if语句共有4种写法: 第一种语法: If 条件判断语句 then 程序代码 第二种语法:If 条件判断语句 then 程序代码 else 程式代码 第三种语法: If 条件 ...
- 有关sass
一.sass编译为css文件 编译的方法有很多 1.koala编译 请参考 http://www.w3cplus.com/blog/777.html http://koala-app.com/ind ...
- ArcGIS API for JavaScript 4.0(一)
原文:ArcGIS API for JavaScript 4.0(一) 最近ArcGIS推出了ArcGIS API for JavaScript 4.0,支持无插件3D显示,而且比较Unity和Sky ...
- background-size的cover和content的用法
background-size:cover; 表示背景图拉伸布满,如果在手机上做的话,背景图片会拉大,失真.这样做不妥 background-size:content; 表示背景图片在内容区域正常显示 ...
- CSS:选择器大全
一.概念: CSS主要的作用就是给网页中的dom元素设置样式,选择器则是用来匹配dom元素的. CSS中的选择器有很多种,常用的分别是标签选择器(根据元素标签名称),类选择器(根据元素class属性) ...
- opencv的高斯混合模型
http://blog.jasonding.top/2015/04/05/Machine%20Learning/%E3%80%90%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%8 ...
- SQL Server Transaction Log Truncate && Shrink
目录 什么是事务日志 事务日志的组成 事务日志大小维护方法 Truncate Shrink 索引碎片 总结 什么是事务日志 Transaction log 是对数据库管理系统执行的一系列动作的记录 ...
- nginx源码学习----内存池
最近在进行监控平台的设计,之前一直觉得C/C++中最棘手的部分是内存的管理上,远不止new/delete.malloc/free这么简单.随着代码量的递增,程序结构复杂度的提高.各种内存方面的问题悄然 ...
- How do you evaluate music?
I’ve seen several “can’t stand” or “best of” threads in regard to music, and based on some related d ...
- sqlplus登陆
cd \sqlplus sys@test_id as sysdba 切换用户SQL> connect system@test_id