Fancybox-无法在Fancybox窗口中打开图像

Fancybox - cannot open image in the Fancybox window

本文关键字:图像 窗口 Fancybox Fancybox-      更新时间:2023-09-26

我一直在为我的照片设置Fancybox窗口,我是这样做的:

$(document).ready(function() {  
  $('.fancybox').fancybox();
});

这是Fancybox的初始化。然后设置链接和图像:

= link_to i.file_url, :class => 'fancybox', :rel => 'gallery', :title => i.title do
  = image_tag i.file_url, :style => 'width: 150px;'

它生成这个HTML代码:

<a href="URL TO FILE" class="fancybox" rel="gallery" title="Item Name">
  <img alt="something" src="URL TO FILE" style="width: 150px;">
</a>

但当我点击链接时,图像会加载在新窗口中,而不是Fancybox窗口中。Fancybox JS+CSS库添加正确-我还缺少什么?

感谢

您的案例中的问题是您的URL模式没有被fancyBox识别。

您应该在选项中明确指定它:

    $('.fancybox').fancybox({type:'image'});