2017-10-10 5 views
1

Shopifyで画像と動画を追加できる製品スライダーの作成にはいくつかの助けが必要です。現時点ではスライダは正常に動作していますが、スライダに製品ビデオを追加する際に問題が発生しています。Shopifyサイトの製品スライダーの画像と動画

私が読んだところでは、altタグを使用して画像を上書きして動画を表示するYouTube埋め込みコードを追加できます。私は最初のイメージでこれを動作させることができますが、残りのスライダを壊すテナントがあります。私は、デフォルトのスライダを変更し、別の方法で頭を動かす必要があると信じています。ここで

は、私がこれまで

$('#FeaturedImageZoom-product-template .product-featured-img').each (function() { 

    var videoid = $(this).attr("alt"); 
    console.log(videoid); 

    if ($('.product-featured-img').attr("alt") == videoid) {   
     $(this).replaceWith('<iframe width="500px" height="500px" src="'+videoid+'?autoplay=1&amp;showinfo=0&amp;controls=0&amp;modestbranding=1&amp;rel=0" frameborder="0" allowfullscreen></iframe>'); 
    } 

    }); 

そして、ここではそれに行くために、液体のコードで持っているものです。

<div class="grid product-single"> 
<div class="grid__item product-single__photos {{ product_image_width }}{% if section.settings.image_size == 'full' %} product-single__photos--full{% endif %}"> 
    {%- assign featured_img_src = current_variant.featured_image.src | default: product.featured_image.src -%} 
    {%- assign featured_img_alt = current_variant.featured_image.alt | default: product.featured_image.alt -%} 
    <div id="FeaturedImageZoom-{{ section.id }}" class="product-single__photo{% if product.images.size > 1 %} product-single__photo--has-thumbnails{% endif %}" {% if enable_zoom %}data-zoom="{{ featured_img_src | img_url: product_image_zoom_size, scale: product_image_scale }}"{% endif %}> 
    <img src="{{ featured_img_src | img_url: product_image_size, scale: product_image_scale }}" alt="{{ featured_img_alt }}" id="FeaturedImage-{{ section.id }}" class="product-featured-img{% if enable_zoom %} js-zoom-enabled{% endif %}"> 
    </div> 

    {% if product.images.size > 1 %} 
    {% if product.images.size > 3 %} 
     {%- assign enable_thumbnail_slides = true -%} 
    {% endif %} 

    <div class="thumbnails-wrapper{% if enable_thumbnail_slides == true %} thumbnails-slider--active{% endif %}"> 
     {% if enable_thumbnail_slides == true %} 
     <button type="button" class="btn btn--link medium-up--hide thumbnails-slider__btn thumbnails-slider__prev thumbnails-slider__prev--{{ section.id }}"> 
      {% include 'icon-chevron-left' %} 
      <span class="icon__fallback-text">{{ 'sections.slideshow.previous_slide' | t }}</span> 
     </button> 
     {% endif %} 
     <ul class="grid grid--uniform product-single__thumbnails product-single__thumbnails-{{ section.id }}"> 
     {% for image in product.images %} 
      <li class="grid__item {{ product_thumbnail_width }} product-single__thumbnails-item"> 
      <a 
       href="{{ image.src | img_url: product_image_size, scale: product_image_scale }}" 
       class="text-link product-single__thumbnail product-single__thumbnail--{{ section.id }}" 
       {% if enable_zoom %}data-zoom="{{ image.src | img_url: product_image_zoom_size, scale: product_image_scale }}"{% endif %}> 
       <img class="product-single__thumbnail-image" src="{{ image.src | img_url: product_thumb_size, scale: product_image_scale }}" alt="{{ image.alt | escape }}"> 
      </a> 
      </li> 
     {% endfor %} 
     </ul> 
     {% if enable_thumbnail_slides == true %} 
     <button type="button" class="btn btn--link medium-up--hide thumbnails-slider__btn thumbnails-slider__next thumbnails-slider__next--{{ section.id }}"> 
      {% include 'icon-chevron-right' %} 
      <span class="icon__fallback-text">{{ 'sections.slideshow.next_slide' | t }}</span> 
     </button> 
     {% endif %} 
    </div> 
    {% endif %} 
</div> 

私は開発者と同様の問題を概説記事のカップルを読んだことがあります製品のビデオを追加しようとしていますが、私はまだ解決策を見つけていません。

誰でも助けてくれれば幸いです。

ありがとう

答えて

2

なぜ簡単に液体を使用することができますか?

youtubeまたは一意のものが含まれている場合は、alt属性のチェックを追加するだけです。

だから例えば:

{% if image.alt contains 'youtube' %} 
    <iframe width="500px" height="500px" src="{{image.alt}}?autoplay=1&amp;showinfo=0&amp;controls=0&amp;modestbranding=1&amp;rel=0" frameborder="0" allowfullscreen></iframe> 
{% else %} 
    <a 
     href="{{ image.src | img_url: product_image_size, scale: product_image_scale }}" 
     class="text-link product-single__thumbnail product-single__thumbnail--{{ section.id }}" 
     {% if enable_zoom %}data-zoom="{{ image.src | img_url: product_image_zoom_size, scale: product_image_scale }}"{% endif %}> 
     <img class="product-single__thumbnail-image" src="{{ image.src | img_url: product_thumb_size, scale: product_image_scale }}" alt="{{ image.alt | escape }}"> 
    </a> 
{% endif %} 
+0

ありがとうございました。私はちょうど間違った方法を考えていたと思う。あなたの答えは、私が必要とした解決策に到達するのを助けました。 – pedz

0

私はちょうど私が「ドリップ」によって、上記の回答に基づいて到着したソリューションを投稿したかったです。私はこれが他の誰かをトラックの下で助けてくれることを望みます。あなたはサムネイルプレースホルダとして画像を使用しているときに、画像のALTタグに埋め込みコードを配置することができ、コードを更新した後

<!-- Product Slider w/ Video --> 
    <div id="product-flexslider" class="flexslider product_gallery product-{{ product.id }}-gallery {% if product-images == blank %}product_slider{% endif %} {% if settings.product_thumbs == false %}animated fadeInUp{% endif %}"> 
    <ul class="slides"> 
     {% for image in product.images %} 
     <li data-thumb="{{ image | product_img_url: '1024x1024' }}" data-title="{% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}{{ product.title }}{% else %}{{ image.alt | escape }}{% endif %}"> 
     {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %} 
     {% assign src = image.alt | split: 'src="' %} 
     {% assign src = src[1] | split: '"' | first %} 

     {% if src contains '?' %} 
     {% assign src = src | append: '&amp;autoplay=1' %} 
     {% else %} 
     {% assign src = src | append: '?autoplay=1' %} 
     {% endif %} 

     <div class="video-container {% if image.alt contains 'vimeo' %}vimeo{% else %}youtube{% endif %}"> 
      <div> 
      <a href="{{ src }}" title="{{ product.title | escape }}"> 
       {{ image.alt }} 
      </a> 
      </div> 
     </div> 
     {% else %} 
     <a href="{{ image | product_img_url: 'master' }}" title="{{ image.alt | escape }}"> 
      <img src="{{ image | product_img_url: '1024x1024' }}" alt="{{ image.alt | escape }}"/> 
     </a> 
     {% endif %} 
     </li> 
     {% endfor %} 
    </ul> 
    </div> 

    <!-- Carousel --> 

    <div id="product-carousel" class="flexslider product_gallery product-{{ product.id }}-gallery {% if product-images == blank %}product_slider{% endif %} {% if settings.product_thumbs == false %}animated fadeInUp{% endif %}"> 
    <ul class="slides"> 
     {% for image in product.images %} 
     <li data-thumb="{{ image | product_img_url: '1024x1024' }}" data-title="{% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}{{ product.title }}{% else %}{{ image.alt | escape }}{% endif %}"> 

     <a href="{{ image | product_img_url: 'master' }}" title="{{ image.alt | escape }}"> 
      <img src="{{ image | product_img_url: '1024x1024' }}" alt="{{ image.alt | escape }}" /> 
     </a> 
     </li> 
     {% endfor %} 
    </ul> 
    </div> 
    <!-- End Slider --> 

<!-- FlexSlider --> 

{{ 'jquery.flexslider-min.js' | asset_url | script_tag }} 
{{ 'flexslider.css' | asset_url | stylesheet_tag }} 


<script type="text/javascript" charset="utf-8"> 
(function($) { 
    $(window).load(function(){ 
    $('#product-carousel').flexslider({ 
    animation: "slide", 
    controlNav: false, 
    itemWidth: 41, 
    itemMargin: 5, 
    asNavFor: '#product-flexslider' 
    }); 
    $('#product-flexslider').flexslider({ 
    animation: "slide", 
    controlNav: false, 
    sync: "#product-carousel" 
    }); 
}); 
})(jQuery); 

</script> 

FlexSliderのプロパティは次の場所にあります。 https://github.com/woocommerce/FlexSlider/wiki/FlexSlider-Properties

溶液はまた別の問題に関連して、ここでポストに助けられました。 https://ecommerce.shopify.com/c/ecommerce-discussion/t/issue-with-variable-image-444159