【问题标题】:fancy box image popup花哨的盒子图像弹出窗口
【发布时间】:2018-05-22 07:35:14
【问题描述】:

我想在点击它时显示图像。我正在使用 Paperclip 来存储图像,并安装了 Fancy-box 来处理图像显示。 但我得到这样的错误。

The requested content cannot be loaded.
Please try again later.

我在 SO 中搜索,发现了类似的问题,Fancybox error in rails 尝试更改建议的链接,但没有结果。

我的 application.js 文件如下所示。

//= require jquery
//= require jquery_ujs
//= require_tree 
//= require fancybox

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

我想要查看图像弹出窗口的显示视图(如本例中的http://fancybox.net/),如下所示。

<a class="fancybox"><%= image_tag @product.photo.url(:thumb) %></a> 

【问题讨论】:

  • 您应该在目标链接中包含&lt;%= @product.photo.url %&gt;

标签: jquery ruby-on-rails fancybox


【解决方案1】:

这里是一个带有源代码的 fancybox 示例:https://www.mgtechnologies.co.in/product/fancybox-responsive-jquery-pop-up

试试这个:

    <a class="fancybox" href="<%= @product.photo.url(:full) %>">
         <%= image_tag @product.photo.url(:thumb) %>
    </a> 

下一个

    $("a.fancybox") - is overhead selector
    $(".fancybox") - enought

点击devTools中的fancybox链接检查网络选项卡后,可能是服务器错误 http://monosnap.com/image/tByHYsWqawv0k5NAVvJrFgpt8

您可以在此处http://fancyapps.com/fancybox/fancybox 的现代文档中找到一些示例并检查 api

尝试解决方法以了解发生了什么:

 $(document).on('click', '.fancybox', (e)->
        $.fancybox.showLoading()
        $.ajax
               url: $(this).attr('href')
               success: (data)->
                 $.fancybox.hideLoading()
                 $.fancybox(data, {
                  afterShow:()->
                     // TODO something
                  overlay :
                    locked : true

                 })

                 true

               dataType: 'html'

        e.preventDefault()
      )

【讨论】:

  • 谢谢,现在当我单击带有http://localhost:3000/system/products/photos/000/000/039/original/CitySkid9V3_9V4.jpg 链接的新窗口中显示的图像时。但为什么图像没有弹出?因为那是我想要实现的,我是否必须在 application.js 文件中添加一些功能才能做到这一点。我以为 Fancy Box 是一个人做的:(
  • 1.你有错误//=需要fancybox路径2。服务器返回带有错误标题的图像。尝试使用 ajax 请求的用户选项 'ajax: { dataType : 'html', headers : { 'X-fancyBox': true } }' 3. 服务器返回带有 js 的 html 内容,破坏了你的页面
【解决方案2】:

请试一试

应用程序.js

//= require jquery
//= require fancybox
//= require jquery_ujs
//= require_tree .

jQuery(function() {
  $("a.fancybox").fancybox();
});

应用程序.css

*= require_self
*= require fancybox
*= require_tree .

您的查看页面

<%= link_to(image_tag(@product.photo.url(:thumb)), @product.photo.url(:full), :class => 'fancybox')%>

【讨论】:

  • 是的,现在我在页面上呈现了图像,但它不像示例中那样弹出。它只显示在页面底部
  • 奇怪!问题:firebug 控制台中是否显示任何 javascript 错误?
  • 这是一个疯狂的猜测:请检查你是否为fancybox添加了css?
  • 我从HERE 下载的文件放在项目文件夹中,现在我有工作图像弹出Like this,但这太糟糕了,因为除了退出按钮之外我没有任何选项来退出这个图像.
  • @Egards,您可以为此使用 gem。请查看github.com/hecticjeff/fancybox-rails。如果您已经下载了fancybox,请检查您的页面,fancybox 的样式表是否正在加载。如果不存在,则需要在 html 中添加 部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-13
  • 2021-03-07
  • 2010-12-01
  • 2014-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多