当前位置: 代码迷 >> 综合 >> cocos2d-js实现网页全屏心得
  详细解决方案

cocos2d-js实现网页全屏心得

热度:15   发布时间:2024-01-29 21:10:48.0

1.如果是H5全屏,使用cc.screen里面的接口就可以完成

判断全屏:cc.screen.isFullScreen()

打开全屏:cc.screen.requestFullScreen(document.documentElement,function(){});

关闭全屏:cc.screen.exitFullScreen();

2.如果是浏览器全屏(F11)使用上面办法就无法判断是否全屏,只能通过浏览器的宽高去判断,重点:火狐浏览器和chrome浏览器判断方式有点区别

var explorer = window.navigator.userAgent.toLowerCase();
if(explorer.indexOf('firefox') > 0){if (window.outerHeight === window.screen.height && window.outerWidth === window.screen.width) {alert('全屏');}else {alert('不是全屏');}
}
else{if (document.body.scrollHeight === window.screen.height && document.body.scrollWidth === window.screen.width) {alert('全屏');}else {alert('不是全屏');}
}