JS隐藏直到浏览器调整大小

我们正在Webflow中建立一个新的电子商务站点,使用Shopify的“立即购买按钮”来允许用户下订单。这对于我们较小的网站来说效果很好,但是在此网站上遇到了一些麻烦。

Webflow在CMS的“集合”中工作,但是用户一次只能过滤一个集合,不可能一次搜索/浏览/过滤所有集合。这意味着用户只能搜索“松饼”或“布朗尼”,而不能同时搜索两者,因为它们是单独的集合。

我正在使用“ Mixitup”过滤这些集合中的项目,效果很好。为了解决一次只能过滤一个Collection的问题,我们使用了一些代码来将显示在同一页面上的所有Collection放在一起,以便一次过滤所有Collection。现在,可以将“布朗尼”和“松饼”一起过滤。

原始Collection的Shopify按钮可以很好地呈现,但是其他任何Collection的Shopify按钮都不能...除非您调整浏览器的大小,否则价格会出现。例如,“松饼”可以正常工作,因为它是页面上的原始收藏,但是现在我们将“布朗尼”作为附加收藏添加,这些价格不会显示,除非您调整浏览器的大小,甚至只是调整像素大小。

在iOS上进行测试,它可以在Safari中呈现搜索结果,因此看起来像是桌面问题?

Here's an example, once loaded, jump to page 4 and see none of the cars have prices until you resize the browser: https://golden-moments-usa.webflow.io/code-test

我搜索了这些论坛并尝试了各种代码段,因为我看到“直到浏览器调整大小后才会显示”,这对其他人来说是个问题,但是老实说,我不确定自己在做什么。

这是用于Shopify按钮的代码:

<div id='product-component-product-component'></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.async = 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: 'product-id',
        node: document.getElementById('product-component'),
        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>
评论