html5>egret>手机浏览器处理适配屏幕问题

<pre name="code" class="javascript" style="color: rgb(68, 68, 68); line-height: 13.1875px;">egret_loader.js
 
 
// ----------------------------------------------------------------------------------------------------------------
    // 手机浏览器解决方案,处理宽和高,如果是生成APP,请另一个原生JS文件,可以参照这种方式.
    var aspectRatio = {portrait: "竖屏", landscape: "横屏"};//横竖屏的处理
    var resolution = {width: 480, height: 800};//默认宽高
    var doResize = function (aspect) {
        var wid, hei, radio;//宽,高,像素比
        //获取窗口宽度
        if (window && window.innerWidth)
            wid = window.innerWidth;
        else if ((document.body) && (document.body.clientWidth))
            wid = document.body.clientWidth;
        //获取窗口高度
        if (window && window.innerHeight)
            hei = window.innerHeight;
        else if ((document.body) && (document.body.clientHeight))
            hei = document.body.clientHeight;
        //通过深入Document内部对body进行检测,获取窗口大小
        if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
            wid = document.documentElement.clientWidth;
            hei = document.documentElement.clientHeight;
        }
        //设备像素比,这里如果获取不到就自动默认为1,如果有特殊需求可以自行修改
        radio = window.devicePixelRatio || 1;
        //处理横竖屏
        if (aspect == null) {
            aspect = aspectRatio.portrait;//横竖屏自己给吧
        }
        resolution = (aspect == aspectRatio.portrait) ? {width: wid, height: hei} : {width: hei, height: wid};
        console.log(aspect, "屏幕宽:", resolution.width, "|", "屏幕高:", resolution.height, "|", "设备像素比:", radio);
        //下面赋值给宽高适配手机浏览器
        egret.StageDelegate.getInstance().setDesignSize(resolution.width * radio, resolution.height * radio);
    };
    doResize();

--


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值