gpt4 book ai didi

javascript - rails 中图像的 fancybox 不起作用

转载 作者:行者123 更新时间:2023-12-03 02:12:45 24 4
gpt4 key购买 nike

我试图显示页面中的所有图像,当单击每个图像时它必须放大,因此为此,我使用了 fancybox。但代码不起作用。我是 Rails 新手,有人可以帮我解决这个问题吗?

_images.html.erb code:
<div class="center" id="images" style="padding:50px 50px 50px 50px;">
<table>
<% @images.each_slice(4) do |images| %>
<tr>
<% images.each do |images| %>
<td style="padding-right:10px;padding-bottom:10px;">
<%= link_to image_tag images, id: '#images', class: "fancybox"
,:size => "300x300" %><br />
</td>
<% end %>
</div>
</tr>
<% end %>
</table>
</div>

/* fancybox code */
$(document).ready(function() {
$("a.fancybox").fancybox();
});

最佳答案

尝试像 doc here 中提到的那样

还要确保images(因此,如果您使用回形针载波,那么它应该是image_url)变量是图像链接,并且在link_to上它需要比 image_tag

更大的图像
  <% images.each do |image| %>
<%= link_to image_url, class: 'fancybox' do%>
<%= image_tag image_url(:thumb), id: 'images', :size => "300x300"%>
<%end%>
<%end%>

关于javascript - rails 中图像的 fancybox 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49484536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com