1

刚开始使用 GWD - 还不错。我控制了大部分,(实际上通常最终通过 DreamWeaver 直接编辑代码而不是 GWD),但不知道如何设置礼貌加载加载图像。任何人都知道如何使用图像填写这些空白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);
    })();
4

3 回答 3

4

根据Google 文档,您应该在 <body> 标记之后放置一个包含加载图像的 <div> :

<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函数中,移除或隐藏图片<div>:

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>

然后在我的主要运行时函数中,我将显示属性设置为“阻止”以再次将其恢复。

<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';

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

于 2015-03-16T23:50:45.837 回答
1

刚开始使用GWD,我也有同样的问题。gwd 将主体不透明度设置为“0”,因为未显示该 loding img。在“gwddoubleclick_min.js”中,gwd 设置主体不透明度。

document.body.style.opacity="0"

我变了;

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

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

document.body.style.opacity=""

改变了;

document.getElementById("gwd-ad").style.opacity="",
document.getElementById('loading').style.display = 'none'

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

于 2016-03-31T08:58:54.563 回答
0

正如 Burak Şahin Erden 在我之前回答的那样,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);
})();

于 2016-05-11T08:58:14.243 回答