移动端默认横屏显示

因为有一个H5页需要横屏,在网上找了找资料,有说通过HTML5 API的,有说不能强制的,所以我就自己优化了一下; 代码中使用了jquery的语法设置,所以需要网页中加载;还有几点需要优化: 1、横屏的时候禁止上向刷新;主要代码如下:/*强制横屏*/ function oScreen(className) { this.className
摘要由CSDN通过智能技术生成

因为有一个H5页需要横屏,在网上找了找资料,有说通过HTML5 API的,有说不能强制的,所以我就自己优化了一下;
代码中使用了jquery的语法设置,所以需要网页中加载;

还有几点需要优化:
1、横屏的时候禁止上向刷新;

限制

测试后,发现在微信,QQ,钉钉中都不能横屏,这是因为APP中限制了,需要打开横屏功能;
1、微信不能横屏,只能用户手动打开,参考:
http://jingyan.baidu.com/article/19020a0a38c36d529c284263.html

看来横屏这功能想用还是有各种困难啊。回头再研究一下!

主要代码如下:

/*强制横屏*/
            function oScreen(className) {
   
                this.className = className;
                var That = this;
                this.conW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
                this.conH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

                console.log('conH:'+this.conH+'conW:'+this.conW)


                var evt = "onorientationchange" in window ? "orientationchange" : "resize";

                window.addEventListener(evt, function() {
   
                    var orientation = window.orientation;
                    switch (orientation){
                        case 90:
                        case -90:
                            orientation = '横'; //这里是横屏,可以console.log()打印出来,可以删除
                            That.vertical(className);
                            break;
                        default
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值