一段代码,给游戏添加统一的封面和旋屏提示

(function(){

function isMobile(){

return navigator.userAgent.match(/android|iphone|ipod|blackberry|meego|symbianos|windowsphone/i);

}

var coverNode = document.createElement("div");

coverNode.style.cssText = "position:absolute;z-index:1000000;left:0;top:0;background:#39445a url(../../cover/cover.jpg) no-repeat center center;"+window.innerWidth+"px;height:"+Math.max(window.innerHeight,window.document.documentElement.offsetHeight)+"px";

coverNode.className = "common_cover";

document.body.appendChild(coverNode);

setTimeout(function(){coverNode.parentNode.removeChild(coverNode)},(COVER_SHOW_TIME || 3000));


if(!isMobile()) return;

document.addEventListener("touchmove",function(e){e.preventDefault();},false);

var noticeNode = document.createElement("div");

noticeNode.className = "common_notice";

noticeNode.style.cssText = "position:absolute;z-index:999999;left:0;top:0;background:#39445a url(../../cover/rotate_tip.jpg) no-repeat center center;";

document.body.appendChild(noticeNode);


function checkCover(){

window.scroll(0,0);

var horizontal;

if(window.orientation == 0 || window.orientation == 180){

horizontal = false;

}else if (window.orientation == -90 || window.orientation == 90){

horizontal = true;

}

if(horizontal == (HORIZONTAL || false)){

noticeNode.style.display = "none";

}else{

setTimeout(function(){

noticeNode.style.width = window.innerWidth+"px";

noticeNode.style.height = window.innerHeight+"px";

noticeNode.style.display = "block";

},(navigator.userAgent.match(/iphone|ipod|ios/i) ? 0 : 600));

}

}

window.addEventListener("orientationchange",checkCover);

window.addEventListener("load",checkCover);

window.addEventListener("scroll",function(){coverNode.style.height=window.innerHeight+"px";coverNode.style.width=window.innerWidth+"px";noticeNode.style.height=window.innerHeight+"px"});

})();


原文地址:https://www.cnblogs.com/cly84920/p/4426461.html