zoukankan      html  css  js  c++  java
  • 一段代码,给游戏添加统一的封面和旋屏提示

    (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"});

    })();


  • 相关阅读:
    Flutter-动画-原理篇
    Flutter-动画-实践篇
    Flutter-动画-概念篇
    Android-textview图文混排(网络图片)
    Android--解决图片保存到相册显示1970年1月1日 8:00的问题
    Android--使用JobService实现进程保活
    Android--获取手机联系人和Sim卡联系人
    git 代码服务器的网页版gitweb的搭建
    Android 内存管理中的 Shallow heap Retained heap
    欧几里德算法----最大公约数算法
  • 原文地址:https://www.cnblogs.com/cly84920/p/4426461.html
Copyright © 2011-2022 走看看