【发布时间】:2015-01-02 16:15:22
【问题描述】:
我正在使用本指南。
问题: 当我点击 [1] [2] 或 [3] 时,主图像没有改变。相反,我被重定向到图像。
查看。 主图:
<div class="block-2-image">
<a href=<%=@advertisement.pictures.first.image.url(:original)%> data-lightbox="gallery"><%= image_tag @advertisement.pictures.first.image.url(:medium),
:title=> @advertisement.name,:id=>"main-image", :alt => @advertisement.name%></a>
</div>
缩略图:
<ul class="thumbnail">
<% @advertisement.pictures.to_enum.with_index(1) do |thumb, index|%>
<li><a href=<%=thumb.image.url(:medium)%>><%= index %></a></li>
<% end %>
</ul>
脚本:
$(document).ready(function(){
$('.thumbnail li').on('click',function(){
$('.block-2-image a').find('img').attr('src', $(this).attr('src'));
});
});
现在,当我单击小图像时,它会链接到正确的图像,但在其他视图中。 我需要在同一视图中更改图像。
有什么帮助吗?
谢谢。
【问题讨论】:
-
Maybe just change image path when click to those number images happen?你试试 -
类似fiddle
-
@BogdanKuštan Tnx。但是我的代码不会改变主图像,它只是重定向到正确的图像路径。脚本有什么问题?
-
@EdgarsRozenfelds 在
click回调函数中您应该传递event参数(在我的示例中为变量e)和内部函数调用event.preventDefault()
标签: javascript jquery html ruby-on-rails image