(横竖屏切换/强制横屏)CSS3 transform 怎样才能中心旋转?
问题描述
现在有一个canvas,我希望在(手机和平板)竖屏时能够把它以中心作为旋转原点旋转90°(强制横屏),但用了transform-origin,无论怎样设置数值都不能达到目的,是我哪里搞错了吗?
附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应该可以实现这个功能,问题是实在太新了,现在的浏览器似乎都不支持,不信你们可以测试下。
(JavaScript)screen.orientation.lock('landscape');
问题解答
回答1:用transform的话貌似不太好吧,毕竟旋转以后尺寸还得再改一遍
相关文章:
1. javascript - node服务端渲染的困惑2. html5 - h5写的app用的webview,用手机浏览器打开不显示?3. javascript - 百度echarts series数据更新问题4. javascript - webpack --hot 热重载无效的问题5. php - 第三方支付平台在很短时间内多次异步通知,订单多次确认收款6. mysql - 一个表和多个表是多对多的关系,该怎么设计7. python - django 按日归档统计订单求解8. 我在导入模板资源时遇到无法显示的问题,请老师解答下9. Mysql && Redis 并发问题10. 请教一个python字符串处理的问题?
