简体   繁体   English

增加移动 shopify 上的横幅宽度

[英]Increase banner width on mobile shopify

I created a page template for a page, using a banner + 2 products.我为一个页面创建了一个页面模板,使用横幅 + 2 个产品。

The issue is on mobile, where I can't make the banner wider.问题出在移动设备上,我无法将横幅加宽。 It stays with some margin left and right, making the image unapropriate for the user xp.它保留了一些左右边距,使图像不适合用户 xp。

I tried using js to make it forcefully wider, but it kept the margin.我尝试使用 js 使其更宽,但它保留了边距。 I even made a function to get the viewport width and set the banner in px to it, with no results.我什至做了一个函数来获取视口宽度并将横幅设置为 px,但没有结果。 Can anyone give me some light?任何人都可以给我一些光吗?

The classes below are premade by the theme creator.以下课程由主题创建者预先制作。

Banner section:横幅部分:

<section  class="parallax-banner parallax-slide slide parallax_effect--{{ section.settings.parallax_effect }}" id="slide-{{ section.id }}">
  <div id="bannerImg" class="bcg {% if section.settings.image == nil %}bcg-placeholder{% endif %}"
      {% if section.settings.parallax_effect %}
        style="background-image:url({% if section.settings.image != nil %}{{ section.settings.image | img_url: '1600x' }}{% else %}{{ 'placeholder.svg' | asset_url }}{% endif %})"
        data-bottom-top="background-position: 50% 200px;"
        data-top-bottom="background-position: 50% -200px;"
        data-anchor-target="#slide-{{ section.id }}"
      {% endif %}
      >
      {% if section.settings.link != blank and section.settings.button_label == blank %}
        <a href="{{ section.settings.link }}" class="full-link">
          {{ section.settings.link }}
        </a>
      {% endif %}
      <div class="hsContainer">
        <img src="{% if section.settings.image != nil %}{{ section.settings.image | img_url: '1600x' }}{% else %}{{ 'placeholder.svg' | asset_url }}{% endif %}" alt="{{ section.settings.image.alt | escape }}" class="hsContainer__image">
        <div class="hsContent">
          <div class="container">
            <div class="columns {% if section.settings.text_position == 'left' %} eight offset-by-one {% elsif section.settings.text_position == 'right' %} eight offset-by-eight {% else %} sixteen {% endif %} align_{{ section.settings.text_alignment }}">
              <div class="{{ section.settings.headline_animation }}">
                {% if section.settings.title != blank %}
... (unecessary code not pasted)

Page template code:页面模板代码:

<div class="container main content main-wrapper">

  <div class="sixteen columns page clearfix">

    <div>
      {% include 'page-multi-column', content: page.content %}
        {% section 'aniversariante-img-overlay' %} 
       {% section 'aniversariante-promocoes' %} 
    </div>
  </div>
</div>

<script>
  var size = getViewportSize().w;
  console.log(size);

 document.getElementsByClassName("hsContainer")[0].style.width = size+"px !important";
 document.getElementsByClassName("hsContainer")[0].style = "margin: 0";

  function getViewportSize(w) {

    // Use the specified window or the current window if no argument
    w = w || window;

    // This works for all browsers except IE8 and before
    if (w.innerWidth != null) return { w: w.innerWidth, h: w.innerHeight };

    // For IE (or any browser) in Standards mode
    var d = w.document;
    if (document.compatMode == "CSS1Compat")
        return { w: d.documentElement.clientWidth,
           h: d.documentElement.clientHeight };

    // For browsers in Quirks mode
    return { w: d.body.clientWidth, h: d.body.clientHeight };

}
</script> 

Live page location: https://clubeporcao.com.br/pages/aniversariante直播页面位置: https : //clubeporcao.com.br/pages/aniversariante

I already tried:我已经尝试过:

  • removing the classes, with result, but broking the page删除类,结果,但破坏了页面
  • removing the container class padding, with no result删除容器类填充,没有结果
  • putting width to % and px将宽度设置为 % 和 px
  • setting margin to 0将边距设置为 0
  • getting into chrome inspect element and try to find where the padding/margin is being set进入 chrome 检查元素并尝试找到设置填充/边距的位置

Hacky solution:哈奇解决方案:

#slide-aniversariante-img-overlay {
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}

Explanation:解释:

You want to make a child element of your .container (which has a fixed width) wider than this container.您想让.container (具有固定宽度)的子元素比此容器更宽。 You know the width of you .container for a picked breakpoint but you can't tell how much space is avaible at the left and right.您知道.container断点的.container的宽度,但您无法确定左侧和右侧有多少可用空间。

You can check it with JavaScript like you already tried, but then you are forced to add an event listener after resizing (because those values will change).您可以像已经尝试过的那样使用 JavaScript 检查它,但是在调整大小后您被迫添加一个事件侦听器(因为这些值会改变)。

Above I've set the child width to 100vw (100% of the viewport width) - so it has a right width but we don't know the value of margin we should use.上面我已经将子宽度设置为 100vw(视口宽度的 100%) - 所以它有一个正确的宽度,但我们不知道我们应该使用的边距值。

We probably could use margin-left: calc( 100vw / 2 - Xpx);我们可能可以使用margin-left: calc( 100vw / 2 - Xpx); where X is the width of .container but instead, I've added position relative and move this slide to the middle width left: 50% - it is 50% of the parent element (if you turn off the transform you will see that the slide starts exactly in the middle of the window).其中 X 是.container的宽度,但相反,我添加了relative位置并将此幻灯片移动到left: 50%中间宽度left: 50% - 它是父元素的 50%(如果关闭transform您将看到幻灯片正好从窗口中间开始)。 transform: translateX(-50%) will set slide in the right place because it works on the child's width not parent's. transform: translateX(-50%)会将幻灯片设置在正确的位置,因为它适用于孩子的宽度而不是父母的宽度。

Caution: For some zoom options, horizontal scroll can appear, you can wrap a banner in a separate section with overflow: hidden;注意:对于某些缩放选项,可能会出现水平滚动,您可以将横幅包装在一个单独的部分中, overflow: hidden; (but if you could do this you probably would remove .container already) or add overflow-x: hidden; (但如果你能做到这一点,你可能已经删除了.container )或添加overflow-x: hidden; to the body.到身体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM