Google Web Designer礼貌加载

时间:2015-02-18 23:47:01

标签: image-preloader google-web-designer

刚开始使用GWD - 还不错。我控制了大部分内容(实际上通常最终通过DreamWeaver直接编辑代码而不是GWD),但无法弄清楚如何设置Polite Load加载图像。任何人都知道如何使用图片logo1.png填写这些空白?我尝试过很多东西,但它总能解决所有问题。

以下是Google提供的初始化代码的相关部分:

      /**
       * Handles the event that is dispatched after the Ad has been
       * initialized and before the default page of the Ad is shown.
       */
      function handleAdInitialized(event) {
        // This marks the end of the polite load phase of the Ad. If a
        // loading image was shown to the user, this is a good place to
        // remove it.
      }

      window.addEventListener('DOMContentLoaded',
        handleDomContentLoaded, false);
      window.addEventListener('WebComponentsReady',
        handleWebComponentsReady, false);
      window.addEventListener('adinitialized',
        handleAdInitialized, false);
    })();

3 个答案:

答案 0 :(得分:4)

根据the Google documentation,你应该放一个< div>包含< body>之后的加载图片标记:

<body style="visibility: hidden;">
  <div id="loading" class="loading-image">
  <img src="logo1.png">
  </div>
  <gwd-doubleclick id="gwd-ad" polite-load="">
  ...
  </gwd-doubleclick>
</body>

然后在handleAdInitialised函数中,删除或隐藏图像&lt; div&gt;:

function handleAdInitialised(event) {
  // This marks the end of the polite load phase of the Ad. If a
  // loading image was shown to the user, this is a good place to
  // remove it.
  document.getElementById('loading').style.display = 'none';
}

您在这里找到的唯一问题是它可能会破坏您在Google Web Designer中的预览。

所以目前我在代码视图中添加一些CSS来隐藏GWD阶段预览中的加载图像:

/* CSS: HIDE OUR LOADING IMAGE */
<style>
.loading-image {
  display: none;
}
</style>

然后在我的主运行时函数中,我将display属性设置为“block”,然后再将其恢复。

<script type="text/javascript" id="gwd-init-code">
  (function() {
    document.body.style.opacity = "0";

    // SHOW OUR LOADING IMAGE AGAIN
    document.getElementById('loading').style.display = 'block';

我认为这应该可以解决问题。

答案 1 :(得分:1)

刚刚开始使用GWD,我有同样的问题。 Gwd将身体不透明度设置为&#34; 0&#34;由于没有显示loding img。在&#34; gwddoubleclick_min.js&#34; gwd设置了身体不透明度。

var x = mainFaires.Select(o => o.trimacid == 27261);

我改变了;

document.body.style.opacity="0"

在每个元素加载后,在同一个文件中;

document.getElementById("gwd-ad").style.opacity="0"

改变;

document.body.style.opacity=""

它对我有用。 有没有人得到不同的解决方案?

答案 2 :(得分:0)

正如BurakŞahinErden在我之前回答的那样,GWD将身体不透明度设置为“0”,这反过来又隐藏了preLoad div。

添加他提到的代码似乎是解决此问题的唯一方法,我的广告现在正如预期的那样使用以下脚本:

<script type="text/javascript" id="gwd-init-code">
(function() {
  document.getElementById("gwd-ad").style.opacity="0"
  document.body.style.opacity=""

  var gwdAd = document.getElementById('gwd-ad');

  document.getElementById('loading').style.display = 'block';

  /**
   * Handles the DOMContentLoaded event. The DOMContentLoaded event is
   * fired when the document has been completely loaded and parsed.
   */
  function handleDomContentLoaded(event) {}

  /**
   * Handles the WebComponentsReady event. This event is fired when all
   * custom elements have been registered and upgraded.
   */
  function handleWebComponentsReady(event) {
    // Start the Ad lifecycle.
    setTimeout(function() {
      gwdAd.initAd();
    }, 0);
  }

  /**
   * Handles the event that is dispatched after the Ad has been
   * initialized and before the default page of the Ad is shown.
   */
  function handleAdInitialized(event) {
    document.getElementById("gwd-ad").style.opacity="",
    document.getElementById('loading').style.display = 'none'
  }

  window.addEventListener('DOMContentLoaded',
    handleDomContentLoaded, false);
  window.addEventListener('WebComponentsReady',
    handleWebComponentsReady, false);
  window.addEventListener('adinitialized',
    handleAdInitialized, false);
})();