admin管理员组文章数量:1563189
<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();
--
版权声明:本文标题:html5>egret>手机浏览器处理适配屏幕问题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727474263a1116379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论