隐藏外部iFrame,直到调整窗口大小

时间:2020-05-11 17:20:16

标签: javascript google-chrome dom shopify

编辑:进一步检查使我认为这是Chrome / Firefox / Edge Mac问题。在Windows,Android和iOS上都可以。看起来好像是Javascript引入的iFrame的高度设置为0px,只有当您调整窗口大小时,Chrome才会“唤醒”并重新调整大小以显示iFrame内容。

我们在Webflow电子商务商店上使用Shopify的“购买按钮”,但是在这种情况下,除非您调整窗口大小,否则某些Shopify按钮/价格将不会显示在台式机(Chrome,Firefox,Edge)上。

以下是我认为要在页面加载中进行的操作:

  1. Shopify按钮脚本将按价格运行加载
  2. 此特定页面使用脚本将一个收藏夹移至另一个收藏夹
  3. 此脚本运行,也许是从Shopify中隐藏了外部iFrame?
  4. 然后,Chrome / Firefox / Edge无法看到这些“已移动”商品的价格

我整天都在寻找解决方案。看来这可能取决于外部iFrame。我正在大声考虑的几个想法:

  • 要删除iFrame吗?
  • 延迟脚本加载,直到完成收藏移动脚本?
  • 加载后调整iFrame的大小以“微调”吗?

这是一个示例页面(请转到第4页以查看问题):https://golden-moments-usa.webflow.io/code-test

这是我正在使用的Shopify按钮代码:

<div id='product-component-{{wf {&quot;path&quot;:&quot;product-component-2&quot;,&quot;type&quot;:&quot;Number&quot;\} }}'></div>
<script type="text/javascript">
/*<![CDATA[*/
(function () {
  var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/buy-button-storefront.min.js';
  if (window.ShopifyBuy) {
    if (window.ShopifyBuy.UI) {
      ShopifyBuyInit();
    } else {
      loadScript();
    }
  } else {
    loadScript();
  }
  function loadScript() {
    var script = document.createElement('script');
    script.defer = true;
    script.src = scriptURL;
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
    script.onload = ShopifyBuyInit;
  }
  function ShopifyBuyInit() {
    var client = ShopifyBuy.buildClient({
      domain: 'golden-moments-usa.myshopify.com',
      storefrontAccessToken: '7d944d2e69bddb24e7c33ba1395129bd',
    });
    ShopifyBuy.UI.onReady(client).then(function (ui) {
      ui.createComponent('product', {
        id: '{{wf {&quot;path&quot;:&quot;product-id&quot;,&quot;type&quot;:&quot;Number&quot;\} }}',
        node: document.getElementById('product-component-{{wf {&quot;path&quot;:&quot;product-component-2&quot;,&quot;type&quot;:&quot;Number&quot;\} }}'),
        moneyFormat: '%24%7B%7Bamount%7D%7D',
        options: {
          
  "product": {
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "calc(25% - 20px)",
          "margin-left": "20px",
          "margin-bottom": "50px"
        },
        "text-align": "left"
      },
      "button": {
        "font-family": "Lato, sans-serif",
        "font-size": "14px",
        "width": "100%",
        "padding-top": "15px",
        "padding-bottom": "15px",
        "color": "#ffffff",
        ":hover": {
          "color": "#ffffff",
          "background-color": "#a81f33"
        },
        "background-color": "#ed2a47",
        ":focus": {
          "background-color": "#13308a"
        },
        "border-radius": "8px",
        "padding-left": "30px",
        "padding-right": "30px"
      },
      "quantityInput": {
        "font-size": "14px",
        "padding-top": "15px",
        "padding-bottom": "15px"
      },
      "price": {
         "font-family": "Lato, serif",
        "font-weight": "700",
        "font-size": "20px",
        "color": "#4d4d4d"
      },
      "compareAt": {
        "font-family": "Lato, serif",
        "font-weight": "bold",
        "color": "#0b1c51"
      }
    },
    "contents": {
      "img": false,
      "button": false,
      "buttonWithQuantity": false,
      "title": false,
      "options": false,
      "price": true
    },
    "googleFonts": [
      "Lato"
    ]
  },
  "productSet": {
    "styles": {
      "products": {
        "@media (min-width: 601px)": {
          "margin-left": "-20px"
        }
      }
    }
  },
  "modalProduct": {
    "contents": {
      "img": false,
      "imgWithCarousel": false,
      "button": true,
      "buttonWithQuantity": false
    },
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "100%",
          "margin-left": "0px",
          "margin-bottom": "0px"
        }
      },
      "button": {
        "font-family": "Lato, sans-serif",
        "font-size": "14px",
        "padding-top": "15px",
        "padding-bottom": "15px",
        "color": "#ffffff",
        ":hover": {
          "color": "#ffffff",
          "background-color": "#ed2a47"
        },
        "background-color": "#0b1c51",
        ":focus": {
          "background-color": "#13308a"
        },
        "border-radius": "8px",
        "padding-left": "30px",
        "padding-right": "30px"
      },
      "quantityInput": {
        "font-size": "14px",
        "padding-top": "15px",
        "padding-bottom": "15px"
      }
    },
    "text": {
      "button": "Add to cart"
    }
  },
  "cart": {
    "styles": {
      "button": {
        "font-family": "Lato, sans-serif",
        "font-size": "14px",
        "padding-top": "15px",
        "padding-bottom": "15px",
        "color": "#ffffff",
        ":hover": {
          "color": "#ffffff",
          "background-color": "#a81f33"
        },
        "background-color": "#ed2a47",
        ":focus": {
          "background-color": "#13308a"
        },
        "border-radius": "8px"
      }
    },
    "text": {
      "total": "Subtotal"
    },
    "contents": {
      "note": true
    }
  },
  "toggle": {
    "styles": {
      "toggle": {
        "font-family": "Lato, sans-serif",
        "background-color": "#ed2a47",
        ":hover": {
          "background-color": "#a81f33"
        },
        ":focus": {
          "background-color": "#13308a"
        }
      },
      "count": {
        "font-size": "14px",
        "color": "#ffffff",
        ":hover": {
          "color": "#c8ad76"
        }
      },
      "iconPath": {
        "fill": "#ffffff"
      }
    }
  }
},
      });
    });
  }
})();
/*]]>*/
</script>

这是正在发生的事情的简短动画:

DOM hidden until resize

0 个答案:

没有答案