简体   繁体   English

Shopify特色产品滑块

[英]Shopify Featured Product Slider

So I have a featured section part of a Shopify website, I initially was going to set up an array of static data and have the featured product fade in/out every few seconds through that. 所以我有一个Shopify网站的特色部分,我最初是要设置一系列静态数据,然后让特色产品每隔几秒钟就淡入/淡出。 However, my JS isn't working yet I am POSITIVE it's correct. 但是,我的JS无法正常工作,我很肯定这是正确的。 Is this a problem with Shopify itself? Shopify本身有问题吗? If anyone could explain to me a way of fading in/out or creating a mini slider for the specific div i'd really appreciate it. 如果有人可以向我解释淡入/淡出或为特定div创建迷你滑块的方法,我将非常感激。

I was attempting to fade out the div ".big-product" 我试图淡出div“ .big-product”

Here is a screenshot to further visualize. 这是进一步可视化的屏幕截图。 特色产品

<h2 class="light">Featured Products</h2>
  {% if collections.frontpage.products.size > 0 %}
    <div class="big-product" id="featprod">

      <div class="product-image" id="product-image">
        <a href="{{ product.url | within: collections.frontpage }}" title="{{ product.title             | escape }} &mdash; {{ product.description | strip_html | truncate: 50 | escape }}"><img src=" {{ product.images.first | product_img_url: 'medium' }}" alt="{{ product.title | escape }}" />                </a>

<div class="product-info">
<h3 class="title"><a href="{{ product.url | within: collections.frontpage }}">{{ product.title }}</a></h3>
<p class="price">
  {{ product.vendor }}
</p>


<p class="description">{{ product.description | strip_html | truncatewords: 40 | escape_html }}</p>

<form action="/cart/add" method="post">
  {% if product.variants.size == 1 %}
    <!-- If there is only 1 variant, only show the purchase button -->
    <input type="hidden" name="id" value="{{ product.variants.first.id }}" id="variant-{{ variant.id }}" />
  {% else %}
    <select name="id">
          {% for variant in product.variants %}
            {% if variant.available %}
                <option value="{{ variant.id }}" id="variant-{{ variant.id }}">             
                {{ variant.title | escape }} for {{ variant.price | money }}
                </option>
            {% else %}
              <option value="{{ variant.id }}" id="variant-{{ variant.id }}" disabled="disabled" class="disabled">              
                {{ variant.title | escape }} &mdash; SOLD OUT
                </option>
            {% endif %}
            {% endfor %}
        </select>
    {% endif %}

  <input type="submit" href="{{ product.url }}" class="button" name="add" value="add to cart" />
  <a href="{{ product.url | within: collections.frontpage }}" class="button">details</a>
</form>

<p class="tags alt">
  {{ product.tags | join: ', ' }}
</p>

Here is a quick slider example. 这是一个快速的滑块示例。 I'm sure there are more elegant ways to achieve the same effect. 我敢肯定,有更多优雅的方法可以达到同样的效果。 I'm just pulling the content 'template' from the features array and putting it in the feature div. 我只是从features数组中拉出内容“模板”,并将其放在feature div中。 And then fading in the content. 然后淡入内容。

var start = 1;

function moveSlider () {  
  $feature.children('div').remove();
  $feature.html(features[start]);
  $feature.children('div').fadeIn();
  start++;

  if (start == features.length) {
    start = 0;
  }
};

setInterval(function () {
  moveSlider();
}, 3000);

Demo 演示

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

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