遇到jquery-smooth-scroll-rails问题

时间:2014-12-11 02:20:43

标签: jquery ruby-on-rails-4 jquery-plugins

我将此添加到我的Gemfile:

group :assets do
  gem 'jquery-smooth-scroll-rails', :git => 'git@github.com:gretel/jquery-smooth-scroll-rails.git'
end

然后我运行bundle install并在我的application.js中包含以下内容:

//= require jquery-smooth-scroll

这就是我在custom.js文件中调用它的方式:

 $('a.scroll-to-form').smoothScroll();

引用此标记创建的元素:

<%= link_to "See your options", "#bottom-form", :class=>"white-btn scroll-to-form" %>

但效果并未呈现。

1 个答案:

答案 0 :(得分:0)

我刚尝试过并且无法使用与rails 4一起使用的gem,但如果我直接添加github目录中的js文件,它工作得很好。 https://raw.githubusercontent.com/kswedberg/jquery-smooth-scroll/master/jquery.smooth-scroll.js

你在jquery-smooth-scroll之后放了custom.js吗? Javascript需要以正确的顺序加载,但如果它的顺序不正确,你会看到javascript控制台中会出现一些错误。 如果你保留// = require树。在application.js中,很可能在jquery平滑滚动之前放置custom.js。

也许您应该使用此代码段确保在custom.js中呈现页面后正在执行javascript:

(function() {
  $(function() {
    return $('.scroll-to-form').click("on", function(e) {
      return $(this).smoothScroll({
        speed: 2000
      });
    });
  });

}).call(this);
相关问题