jquery - 为图像添加灯箱

标签 jquery css ruby-on-rails magnific-popup

我没有 CSS 和 JQuery 经验。因此,我对使用我的应用程序实现 Magnific Popup 感到迷失。我正在使用https://github.com/joshuajansen/magnific-popup-rails 。我在 View 中插入的代码显示在页面本身上。我按照 github 上的内容进行操作,然后将代码添加到 View 中。

<h1><%= @user.username %></h1>

<div class="parent-container">

$(document).ready(function() {
  $('.parent-container').magnificPopup({
    delegate: 'a',
    type: 'image'
  });   
});

<% @user.photos.each do |photo| %>
    <%= link_to image_tag(photo.image_url(:thumb)), photo.image_url%>

</div>
<% end %>

最佳答案

我对 ruby​​ on Rails 的了解相当有限,但我很确定您需要将 javascript 包含在脚本标记中,如下所示:

<script type="text/javascript">
    $(document).ready(function() {
        $('.parent-container').magnificPopup({
            delegate: 'a',
            type: 'image'
        });   
    });
</script>

<div class="parent-container">
    <% @user.photos.each do |photo| %>
        <%= link_to image_tag(photo.image_url(:thumb)), photo.image_url%>
</div>

关于jquery - 为图像添加灯箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19502773/

相关文章:

javascript - 为什么我的 find ('a' ) 在 jquery 中不起作用?

javascript - 在 jQuery 中分解一个字符串

javascript - 更改 Font Awesome 星形图标的颜色

html - 邻居之间的垂直边距不一致

ruby-on-rails - 有必要force_ssl吗?或者 SSL 应该在负载均衡器处终止吗?

ruby-on-rails - rails - 使用 Rails.cache 会出错

ruby-on-rails - 无论如何让RubyMine选择像Intellij Idea一样的第一个完成选择?

javascript - jQuery 在滚动时动画一次

html - 如何使用边距 : auto 使容器居中

css - Bootstrap 3 - 禁用导航栏折叠