| 12345678910111213141516171819202122232425262728293031 |
- const {ccclass, property} = cc._decorator;
- import lib = require("../BiBeng/Library");
- @ccclass
- export default class CanvasFitter extends cc.Component {
- @property({
- type: cc.Canvas
- })
- canvas: cc.Canvas = null;
- onLoad() {
- console.log("userAgent", navigator.userAgent.toLowerCase());
- if (!lib.openInWebview() && this.checkPC()) {
- this.canvas.fitHeight = true;
- }
- this.canvas.node.active = true;
- }
- /**
- * 检测是否运行在pc端浏览器
- * @returns 页面在pc端打开时,返回true;否则返回false
- */
- checkPC(): boolean {
- var agentstr = navigator.userAgent.toLowerCase();
- var agentreg = /(iphone|ipod|ipad|android|symbianos|windows phone|playbook|mobile)/;
- var agentph = agentstr.match(agentreg);
- if (agentph) return false;
- return true;
- }
- }
|