elevateweb / elevatezoom

1.02k stars 493 forks source link

Image zoom with thumbnails on Rails #171

Closed htorohn closed 6 years ago

htorohn commented 6 years ago

Hello, first of all, congratulations on the excellent work. I'm developing a rails commerce application and I'm using elevate zoom to create a zoom on the product's images. so far is working very good with just the main image, but I cannot make it work when selecting different thumbnails and changing the main image when I click on a thumbnail (keeps zooming the first image).

I went through the examples with the galleries and the complexity of my application is when generating the thumbnails.

Can you please help me!

snip20170922_1

Here is the code to generate the thumbnails:

<% if (@product.images + @product.variant_images).uniq.size > 1 %>

<ul id="product-thumbnails" class="product-slider thumbnails list-inline" data-hook> <% @product.images.each do |i| %> <div class="item"> <li class='tmb-all tmb-<%= i.viewable.id %>'> <%= link_to(image_tag(i.attachment.url(:mini), class: "thumbnail", 'data-zoom-image' => i.attachment.url(:large)), i.attachment.url(:product)) %> </li> </div> <% end %>

<% if @product.has_variants? %>
  <% @product.variant_images.each do |i| %>
    <% next if @product.images.include?(i) %>
   `<div class="item">`
   `<li class='vtmb tmb-<%= i.viewable.id %>'>`
      <%= link_to(image_tag(i.attachment.url(:mini), class: "thumbnail", 'data-zoom-image' => i.attachment.url(:large)), i.attachment.url(:product)) %>
      `</li>`
    `</div>`
  <% end %>
<% end %>

</ul>

<% end %>