解决移动端开发H5页面点击按钮后出现闪烁或黑色背景
*{
-webkit-tap-highlight-color:transparent;
}
设备识别
function isPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for (var i = 0; i < Agents.length; i++) {
if (userAgentInfo.indexOf(Agents[i]) > 0) {
flag = false;
break;
}
}
return flag;
}
function isMobile() {
var u = navigator.userAgent;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
return "Android!";
} else if (u.indexOf('iPhone') > -1) {
return "iPhone!";
} else if (u.indexOf('iPad') > -1) {
return "iPad!";
} else if (u.indexOf('Windows Phone') > -1) {
return "Windows Phone!";
} else {
return false;
}
}
function isWeChat() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('micromessenger') != -1) {
return true;
} else {
return false;
}
}
alert(`是否PC: ${isPC()} \n是否移动端: ${isMobile()} \n是否微信: ${
isWeChat()}`);
全屏非全屏互切
function requestFullScreen() {
const {
documentElement } = document;
if (documentElement.requestFullscreen) {
documentElement.requestFullscreen();
} else if (documentElement.mozRequestFullScreen) {
documentElement.mozRequestFullScreen();
} else if (documentElement.webkitRequestFullScreen) {
documentElement.webkitRequestFullScreen();
}
}
function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}