【问题标题】:Remove everything from the page and replace it with the unity game onclick [closed]从页面中删除所有内容并将其替换为统一游戏 onclick [关闭]
【发布时间】:2021-12-23 13:12:04
【问题描述】:

标题是不言自明的。我试图隐藏一个隐藏的 href,单击该 href 会擦除页面上的所有内容,将其留空一秒钟,然后将统一游戏作为整个页面插入。

这是我到目前为止所得到的。

<!DOCTYPE html>
<html>
  <script>
    function wipeHTML() {
      document.documentElement.innerHTML = nothing; //NEED HELP HERE
      then wait 1 second
      document.documentElement.innerHTML = unity game loads; //NEED HELP HERE
    }

  </script>
  <!-- UNITY STUFF -->

  <head>
    <link rel="stylesheet" href="TemplateData/style.css">
    <script src="TemplateData/UnityProgress.js"></script>
    <script src="TemplateData/unityloader41.js"></script>
    <script>
      var gameInstance = UnityLoader.instantiate("gameContainer", "Build/slope.json", {
        onProgress: UnityProgress,
        Module: {
          onRuntimeInitialized: function() {
            UnityProgress(gameInstance, "complete")
          }
        }
      });

    </script>
  </head>

  <body style="margin: 0; overflow: hidden;">
    <div class="webgl-content">
      <div id="gameContainer" style="width: 100%; height: 100%; margin: 0;"></div>
    </div>
  </body>
  <!-- UNITY STUFF END -->
  <h1>
    <a href="javascript:wipeHTML">wipe everything</a>
  </h1>
  <div>
    <h1>
      hello
    </h1>
    <h3>
      erase me
    </h3>
  </div>

告诉我我做错了什么! ????‍♂️

【问题讨论】:

    标签: javascript html jquery function unity3d


    【解决方案1】:

    清除页面正文:

    document.body = document.createElement("body");
    

    要显示游戏,请添加超时,将 console.log 替换为显示游戏的代码。

    setTimeout(() => console.log("load unity here"), 5e3)
    

    【讨论】:

      猜你喜欢
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      • 1970-01-01
      • 2018-03-26
      • 2021-08-26
      • 2015-05-03
      • 1970-01-01
      相关资源
      最近更新 更多