在不禁用 iFrame 的情况下修改 Shopify Buy Button 的产品变体下拉列表的宽度、高度和位置

Modify the width, height and position of product variant drop-down for a Shopify Buy Button without disabling the iFrame

我需要将产品变体下拉菜单的高度更改为正好 42 像素(与购买按钮的高度相同),将宽度更改为正好 80 像素。此外,我需要直接将产品变体下拉菜单放置在购买按钮上方,而不是放在购买按钮左侧。

我试图在 Shopify 论坛中找到有关如何执行此操作的文章,但还没有找到,而且我不确定这些元素在嵌入式代码中的哪些位置会发生变化。 Shopify 也不为其购买按钮提供自定义支持。我不想禁用 iFrame。

JSFiddle:https://jsfiddle.net/johnsmithh/eo4rzLwc/2/

代码:

<div id="product-component-1580935128063">
<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: 'missingnewyork.myshopify.com',
      storefrontAccessToken: '8ad1e9d2d113621e1e9785f5a84b7330',
    });
    ShopifyBuy.UI.onReady(client).then(function (ui) {
      ui.createComponent('product', {
        id: '4448713736258',
        node: document.getElementById('product-component-1580935128063'),
        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"
        }
      },
      "button": {
        "font-weight": "bold",
        "color": "#000000",
        ":hover": {
          "color": "#000000",
          "background-color": "#e6e6e6"
        },
        "background-color": "#ffffff",
        ":focus": {
          "background-color": "#e6e6e6"
        },
        "border-radius": "5px"
      },
    },
      "option": {
          "display": "inline-block",
          "width": "20px",
      },  
    "contents": {
      "img": false,
      "title": false,
      "price": false
    },
    "text": {
    "outOfStock": "SOLD OUT"
    },    
  },
  "productSet": {
    "styles": {
      "products": {
        "@media (min-width: 601px)": {
          "margin-left": "-20px"
        }
      }
    }
  },
  "modalProduct": {
    "contents": {
      "img": false,
      "imgWithCarousel": true,
      "button": false,
      "buttonWithQuantity": true
    },
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "100%",
          "margin-left": "0px",
          "margin-bottom": "0px"
        }
      },
      "button": {
        "font-weight": "bold",
        "color": "#000000",
        ":hover": {
          "color": "#000000",
          "background-color": "#e6e6e6"
        },
        "background-color": "#ffffff",
        ":focus": {
          "background-color": "#e6e6e6"
        },
        "border-radius": "5px"
      }
    },
    "text": {
      "button": "ADD TO CART"
    }
  },
  "cart": {
    "styles": {
      "button": {
        "font-weight": "bold",
        "color": "#000000",
        ":hover": {
          "color": "#000000",
          "background-color": "#e6e6e6"
        },
        "background-color": "#ffffff",
        ":focus": {
          "background-color": "#e6e6e6"
        },
        "border-radius": "5px"
      },
      "title": {
        "color": "#ffffff"
      },
      "header": {
        "color": "#ffffff"
      },
      "lineItems": {
        "color": "#ffffff"
      },
      "subtotalText": {
        "color": "#ffffff"
      },
      "subtotal": {
        "color": "#ffffff"
      },
      "notice": {
        "color": "#ffffff"
      },
      "currency": {
        "color": "#ffffff"
      },
      "close": {
        "color": "#ffffff",
        ":hover": {
          "color": "#ffffff"
        }
      },
      "empty": {
        "color": "#ffffff"
      },
      "noteDescription": {
        "color": "#ffffff"
      },
      "discountText": {
        "color": "#ffffff"
      },
      "discountIcon": {
        "fill": "#ffffff"
      },
      "discountAmount": {
        "color": "#ffffff"
      },
      "cart": {
        "background-color": "#000000"
      },
      "footer": {
        "background-color": "#000000"
      }
    },
    "text": {
      "title": "CART",
      "empty": "YOUR CART IS EMPTY.",
      "notice": "Shipping and taxes are added at checkout.",    
    }
  },
  "toggle": {
    "styles": {
      "toggle": {
        "font-weight": "bold",
        "background-color": "#ffffff",
        ":hover": {
          "background-color": "#e6e6e6"
        },
        ":focus": {
          "background-color": "#e6e6e6"
        }
      },
      "count": {
        "color": "#000000",
        ":hover": {
          "color": "#000000"
        }
      },
      "iconPath": {
        "fill": "#000000"
      }
    }
  },
  "lineItem": {
    "styles": {
      "variantTitle": {
        "color": "#ffffff"
      },
      "title": {
        "color": "#ffffff"
      },
      "price": {
        "color": "#ffffff"
      },
      "fullPrice": {
        "color": "#ffffff"
      },
      "discount": {
        "color": "#ffffff"
      },
      "discountIcon": {
        "fill": "#ffffff"
      },
      "quantity": {
        "color": "#ffffff"
      },
      "quantityIncrement": {
        "color": "#ffffff",
        "border-color": "#ffffff"
      },
      "quantityDecrement": {
        "color": "#ffffff",
        "border-color": "#ffffff"
      },
      "quantityInput": {
        "color": "#ffffff",
        "border-color": "#ffffff"
      }
    }
  }
},
      });
    });
  }
})();
/*]]>*/
</script>
</div>

谢谢!

你有几个选择。我的建议是完全删除 iFrame 并在 CSS 文件中设置样式。它看起来像这样:

        moneyFormat: '%24%7B%7Bamount%7D%7D',
        options: {
       "product": {
         "iframe": false,
         ...
          }
       }

您可以找到有关它的更多信息 here,只需跳至 "Custom styling without iframes"。还有一些其他的选择,但我相信这个是最好的,可以完全控制你想要的。

请记住,它自然会弄乱预先构建的 CSS。 Here is an example I coded for you.