CSS旋轉與翻轉使用樣本詳解

來源:互聯網
上載者:User

標籤:style   io   os   使用   for   sp   on   c   代碼   

      css 2.0還是沒有翻轉的,3.0裡面有rotate屬性,這個可以把元素進行任意角度旋轉,灰常強大,下面有個不錯的樣本,大家可以參考下

一個項目中要畫一個圖,有橫座標和縱座標,縱座標需要文字轉過來豎排,baidu了一圈,找到一篇文章,有用,轉載過來備查

css 2.0還是沒有翻轉的,3.0裡面有rotate屬性,這個可以把元素進行任意角度旋轉,灰常強大。除了這個rotate,還有一個scale,一般用法格式是

-moz-transform:scale(1,1);

括弧裡面(1,1)前者表示X軸,後者表示Y軸,當數字大於1時放大,大於0並小於1時縮小,很好理解,那麼負數是怎樣的效果?答案是 翻轉 。

-moz-transform:scale(-1,1);

表示水平翻轉;

-moz-transform:scale(1,-1);

表示垂直翻轉。

不過這些都是moz或者webkit的,萬惡的IE怎麼辦?
於是我們想到濾鏡,濾鏡裡面有這麼一堆東西:

順時針旋轉圖片90度
picID.style.filter="progid:DXImageTransform.Microsoft.BasicImage(rotation=1)";
旋轉180度
picID.style.filter="progid:DXImageTransform.Microsoft.BasicImage(rotation=2)";
逆時針旋轉90度
picID.style.filter="progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";

有沒有想問“rotation=4”什麼效果? 面壁去...90、180、270都出來了,還要rotation=4實現360幹嘛,感覺這個很費呢。不過這個是靜態費,如果動態話,這個就是必須的了。假如用js控制元素旋轉,從0順時針旋到270的時候,如果沒有360的話,那麼270會快速的逆時針回到0,這樣就2了,所以要給個360過渡,讓270自然到360,然後再迴圈,這樣就流暢了……

這跟css3的rotate差不多,不過只能固定角度的旋轉,來個順時針15度就沒折了,css確實很輕鬆的transform:rotate(15deg);

不過這樣也只是實現了“旋轉”,還有“翻轉”沒實現。IE的翻轉就需要用到這個:

水平翻轉:filter:FlipH;
垂直翻轉:filter:FlipV;

這樣就齊全了

具體代碼:
1、水平翻轉-moz-transform:scale(-1,1);
-webkit-transform:scale(-1,1);
-o-transform:scale(-1,1);
transform:scale(-1,1);
filter:FlipH;

2、垂直翻轉
-moz-transform:scale(1,-1);
-webkit-transform:scale(1,-1);
-o-transform:scale(1,-1);
transform:scale(1,-1);
filter:FlipV;

3、順時針旋轉90度

-moz-transform:rotate(90deg);
-webkit-transform:rotate(90deg);
-o-transform:rotate(90deg);
transform:rotate(90deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=1);

CSS旋轉與翻轉使用樣本詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.