ionic 横竖屏的切换

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

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

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

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

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

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

猜你喜欢

转载自blog.csdn.net/weixin_43806483/article/details/84570055