轉載請說明出處,原文地址http://blog.sina.com.cn/s/blog_780a942701014xl8.htmlhtml
目前這兩個屬性獲得了除去ie之外各個主流瀏覽器webkit,firefox,opera的支持,屬性名分別爲web
-webkit-transform,-moz-transform,-o-transform;瀏覽器
一、改變元素基點transform-originurl
transform-origin(X,Y):用來設置元素的運動的基點(參照點)。默認點是元素的中心點。其中X和Y的值能夠是百分值,em,px,其中X也能夠是字符參數值left,center,right;Y和X同樣除了百分值外還能夠設置字符值top,center,bottom 。spa
其中 left,center right是水平方向取值,對應的百分值爲left=0%;center=50%;right=100%firefox
而orm
top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%;htm
若是只取一個值,表示垂直方向值不變。對象
注:blog
transform-origin並非transform中的屬性值,他具備本身的語法。
可是他要結合transform才能起做用。
例子:
初始態:
.heart{ position:relative; width:100px; height:80px; background:blue;}
.heart:before{ position:absolute; content:""; left:50px;top:0;width:50px;height:80px; background:red;border-radius: 50px 50px 0 0;}
取基點爲左下角,逆時針轉45deg
.heart{ position:relative; width:100px; height:80px; background:blue;}
.heart:before{ position:absolute; content:""; left:50px;top:0;width:50px;height:80px; background:red;border-radius: 50px 50px 0 0; -webkit-transform: rotate(-45deg); -webkit-transform-origin: 0 100%;}
取右下角爲基點旋轉:
.heart{ position:relative; width:100px; height:80px; background:blue;}
.heart:before{ position:absolute; content:""; left:50px;top:0;width:50px;height:80px; background:red;border-radius: 50px 50px 0 0; -webkit-transform: rotate(-45deg); -webkit-transform-origin: 0 100%;}
.heart:after{ position:absolute; content:""; left:0px;top:0;width:50px;height:80px; background:yellow;border-radius: 50px 50px 0 0; -webkit-transform: rotate(45deg); -webkit-transform-origin: 100% 100%;}
.heart:before,.heart:after{ position:absolute; content:""; top:0;width:50px;height:80px; background:red;border-radius: 50px 50px 0 0;}
.heart:before{ left:50px; -webkit-transform: rotate(-45deg); -webkit-transform-origin: 0 100%;}
.heart:after { left: 0; -webkit-transform: rotate(45deg); -webkit-transform-origin: 100% 100%;}
二、transform