ionic 横竖屏的切换

当表格的列数比较多,一屏展现不全时,须要进行横竖屏的切换。
cordova-plugin-screen-orientation 2.0.2
1 安装插件
cordova plugin add cordova-plugin-screen-orientation
2 添加屏幕配置html

<pre name="code" class="html">
<preference name="orientation" value="portrait" />

3 注意项
orientation设置可让你锁定应用程序屏幕方向以阻止屏幕自动翻转。可选的值有:default,landscape(横屏),portrait(竖屏)。
landscape(横屏)表示横屏显示。
portrait(竖屏)表示竖屏显示。
4 相关用法web

window.screen.orientation.lock('landscape');   屏幕锁定横屏
window.screen.orientation.lock('portrait');   屏幕锁定竖屏
screen.orientation.unlock();    屏幕解锁

注 须要注意 总体上对横竖屏控制时,避免出现样式混乱的状况。
5 屏幕切换时函数svg

window.addEventListener("orientationchange", function(){
        alert(screen.orientation.type); // e.g. portrait
    });
    screen.orientation.addEventListener('change', function(){
        console.log(screen.orientation.type); // e.g. portrait
    });