Display correct image with coffeescript fancybox-rails -


i have thumbnails, when click them image displayed in .big-img. use fancybox-rails display image in full-size. works great, problem selected thumbnail displayed fancybox. right path leads first image, no matter thumbnail displayed in big-img, first image displayed fancybox.

html.erb

<%=link_to (@product.images.first.url), :class => 'fancyframe', :rel => 'group' %>    <div class="big-img"> <%= image_tag(@product.images.first.url) %></div> <% end %>  <% if @product.images.count > 1 %>   <% @product.images.each |image| %>         <%= link_to image_tag((image.url), :class => 'thumb')%>   <% end %> <% end %> 

js.coffee

jquery ->  $(".thumb").click ->   val = $(this).attr("src")   $(".big-img").html "<img src=\"" + val + "\" />"   return false;  jquery ->  $(".fancyframe").fancybox   type: "iframe"   width: 900    height: 1000           

i don't know either coffescript or rails looking @ code guess script

<%=link_to (@product.images.first.url), :class => 'fancyframe', :rel => 'group' %>    <div class="big-img"> <%= image_tag(@product.images.first.url) %></div> <% end %> 

renders html (at end matters)

<a href="{image first url}" class="fancyframe" rel="group">     <div class="big-img">         <img src="{image first url}" />     </div> </a> 

then script

jquery ->  $(".thumb").click ->   val = $(this).attr("src")   $(".big-img").html "<img src=\"" + val + "\" />"   return false; 

...changes thumbnail image (<img /> tag) inside container <div class="big-img"> href of parent link (<a> tag class="fancyframe") still pointing first image url.

you have change href of .fancyframe selector

jquery ->  $(".thumb").click ->   val = $(this).attr("src")   $(".big-img").html "<img src=\"" + val + "\" />"   $(".fancyframe").attr("href", val); // write in coffescript format   return false; 

see jsfiddle


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -