(橫豎屏切換/強制橫屏)CSS3 transform 怎樣才能中心旋轉(zhuǎn)?
問題描述
現(xiàn)在有一個canvas,我希望在(手機和平板)豎屏?xí)r能夠把它以中心作為旋轉(zhuǎn)原點旋轉(zhuǎn)90°(強制橫屏),但用了transform-origin,無論怎樣設(shè)置數(shù)值都不能達到目的,是我哪里搞錯了嗎?
附CSS代碼:
html, body{ width: 100%; height: 100%; margin: 0; padding: 0; background: #000000; -webkit-touch-callout: none; -webkit-user-select: none;}#main //div{ margin: 0; width: 100%; height: 100%; display: block; background: #000000; z-index: 10;}#live //在main里面的canvas{ background-size: cover; -moz-background-size: cover; -webkit-background-size: cover; -o-background-size: cover; z-index: 20;}@media all and (orientation : landscape){ #live {margin: 0 auto;padding: 0;display: block;background-size: cover;-moz-background-size: cover;-webkit-background-size: cover;-o-background-size: cover;z-index: 20; }}@media all and (orientation : portrait){ #live {transform: rotate(90deg);transform-origin: center center;-ms-transform: rotate(90deg); /* Internet Explorer 9 */-ms-transform-origin: center center; /* Internet Explorer 9 */-moz-transform: rotate(90deg); /* Firefox */-moz-transform-origin: center center; /* Firefox */-webkit-transform-origin: center center; /* Safari & Chrome */-webkit-transform: rotate(90deg); /* Safari & Chrome */-o-transform: rotate(90deg); /* Opera */-o-transform-origin: center center; /* Opera */margin: 0 auto;padding: 0;display: block;background-size: cover;-moz-background-size: cover;-webkit-background-size: cover;-o-background-size: cover;z-index: 20; }}
PS: W3C新出的屏幕方向API應(yīng)該可以實現(xiàn)這個功能,問題是實在太新了,現(xiàn)在的瀏覽器似乎都不支持,不信你們可以測試下。
(JavaScript)screen.orientation.lock('landscape');
問題解答
回答1:用transform的話貌似不太好吧,畢竟旋轉(zhuǎn)以后尺寸還得再改一遍
相關(guān)文章:
1. angular.js - angular內(nèi)容過長展開收起效果2. dockerfile - [docker build image失敗- npm install]3. golang - 用IDE看docker源碼時的小問題4. docker-compose中volumes的問題5. python打開.py文件的時候出現(xiàn)window無法打開該文件是怎么回事呢?6. android - 如何實現(xiàn)QQ pad 點擊右側(cè)輸入框,只頂右側(cè)的布局,左側(cè)布局不動7. node.js - 微信的自動回復(fù)問題8. 用Python調(diào)用api之后,沒有輸出該如何解決?9. javascript - js代碼轉(zhuǎn)python10. 兩個思路:python模擬登陸頁面和模擬操作windows程序窗口提交請求

網(wǎng)公網(wǎng)安備