我将这个https://bootsnipp.com/snippets/55Z0v Bootstrap轮播添加到rails应用程序中。
我想在Carousel中展示的图片来自image.rb
模型。
当我添加逻辑以在旋转木马中显示图像时,它们就会出现在彼此之上。
我不知道该怎么做,但据我所知,Carousel正在显示所选产品的所有图片。
之前我曾使用过bootstrap轮播,但仅限于纯html / css,所以在Rails应用程序中使用它对我来说是新的。
有人可以告诉我如何使图像看起来像正常情况一样吗?
以下是show.html.erb
<div class="container">
<div id='carousel-custom' class='carousel slide' data-ride='carousel'>
<div class='carousel-outer'>
<!-- me art lab slider -->
<div class='carousel-inner '>
<div class='item active'>
<% @product.images.each do |image_product| %>
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "zoom_05" %>
<% end %>
</div>
<script>
$("#zoom_05").elevateZoom({ zoomType : "inner", cursor: "crosshair" });
</script>
</div>
<!-- sag sol -->
<a class='left carousel-control' href='#carousel-custom' data-slide='prev'>
<span class='glyphicon glyphicon-chevron-left'></span>
</a>
<a class='right carousel-control' href='#carousel-custom' data-slide='next'>
<span class='glyphicon glyphicon-chevron-right'></span>
</a>
</div>
<!-- thumb -->
<ol class='carousel-indicators mCustomScrollbar meartlab'>
<li data-target='#carousel-custom' data-slide-to='0' class='active'>
<% @product.images.each do |image_product| %>
<%= image_tag image_product.image.url(:small), class: "img-responsive", id: "zoom_05" %>
<% end %>
</li>
</ol>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".mCustomScrollbar").mCustomScrollbar({axis:"x"});
});
</script>
</div>
答案 0 :(得分:1)
如果我没有弄错的话,问题是图像的所有父级div
都有item active
个类,并且只能有active
类。
另请查看data-slide-to
元素中li
s的ol
属性。
<li data-target='#carousel-custom' data-slide-to='0' class='active'> <% @product.images.each do |image_product| %> <%= image_tag image_product.image.url(:small), class: "img-responsive", id: "zoom_05" %> <% end %> </li>
你是alwasys在零位置添加幻灯片。
必须是这样的:
<div class="container">
<div id='carousel-custom' class='carousel slide' data-ride='carousel'>
<div class='carousel-outer'>
<!-- me art lab slider -->
<div class='carousel-inner '>
<% @product.images.each_with_index do |image_product, index| %>
<div class="<%= index == 0 ? 'item active' : 'item' %>" >
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "<%= index == 0 ? 'zoom_05' : '' %>" %>
</div>
<% end %>
<script>
$("#zoom_05").elevateZoom({ zoomType : "inner", cursor: "crosshair" });
</script>
</div>
<!-- sag sol -->
<a class='left carousel-control' href='#carousel-custom' data-slide='prev'>
<span class='glyphicon glyphicon-chevron-left'></span>
</a>
<a class='right carousel-control' href='#carousel-custom' data-slide='next'>
<span class='glyphicon glyphicon-chevron-right'></span>
</a>
</div>
<!-- thumb -->
<ol class='carousel-indicators mCustomScrollbar meartlab'>
<% @product.images.each_with_index do |image_product, index| %>
<li data-target='#carousel-custom' data-slide-to="<%= index %>" class="<%= index == 0 ? 'active' : '' %>" >
<%= image_tag image_product.image.url(:small), class: "img-responsive", id: "" %>
</li>
<% end %>
</li>
</ol>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".mCustomScrollbar").mCustomScrollbar({axis:"x"});
});
</script>
</div>
在带有index == 0
的迭代器中,我检查它是否是第一个设置active
类的图像。
另外,同样的事情,我在li's
内的ol
设置了slide-to
属性。