javascript - bootstrap-gallery,激活画廊容器上的插件

标签 javascript ruby-on-rails twitter-bootstrap

我正在尝试使用bootstrap-gallery在我的 Rails 4 应用程序中。

我遵循了简单的说明,但不理解其含义:

3.  activate the plugin on the gallery container

$('.gallery').bootstrapGallery();

我尝试将其添加到我的 View 顶部:

<script>
$('.gallery').bootstrapGallery();
</script>

但是当我点击图像时,JS 似乎没有执行(我只是转到图像 URL),并且在 JS 控制台中收到以下错误:

Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined
Uncaught TypeError: Cannot call method 'addMarker' of undefined

请指出我哪里出错了?

编辑:这是我的看法:

<%= javascript_include_tag "bootstrap-gallery" %>
<%= stylesheet_link_tag "bootstrap-gallery" %>

<div class="gallery row">
  <% @post.assets.each do |asset| %>
     <a class="col-xs-6 col-sm-4" href=<%= asset.asset.url(:medium) %>>
       <img src=<%= asset.asset.url(:medium) %> alt="">
     </a>
  <% end %>
</div>

<script>
var ready;
ready = function() {
  $('.gallery').bootstrapGallery();
};

$(document).ready(ready);
$(document).on('page:load', ready);
</script>

仍然遇到同样的问题:

Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined

最佳答案

尝试:

$('.gallery').bootstrapGallery({});

出于某种原因,脚本期望将选项传递给它;如果您不需要更改任何内容,可以将选项设置为空。

关于javascript - bootstrap-gallery,激活画廊容器上的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26288255/

相关文章:

javascript - 如何将 requestAnimationFrame 与 Motorcycle 和 mostjs 一起使用

javascript - 悬停样式和过渡不适用于 Firefox 中的附加元素

javascript - 遍历 jQuery 数组

html - 从 All_Users 页面链接到用户配置文件、路由

sql - 在 id 字段上重置种子的 Rails 方法

button - 当按钮处于加载状态时,如何向按钮添加微调器图标?

javascript - 解析获取没有任何实际数据的对象

ruby-on-rails - #<Array :> in ActiveAdmin row 的未定义方法 `name'

javascript - jquery-数据表 : incorrect "Showing <range> of <total> entries" message is displayed

html - 如何使我的可滚动水平画廊以三张图片中的第一张为中心并使用 Bootstrap 进行响应?