如何获得jQuery的动画中的Rails 3.2.8工作?(How to get jquery an

2019-10-30 01:44发布

我使用jQuery的animate()方法在我的Rails应用程序。

但是,我不能得到它的工作。

这是我application.js文件:

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

我尝试添加//= require jquery-ui在那里,但它引起我的应用程序崩溃:

couldn't find file 'jquery-ui'

谁能告诉我,我缺少的是什么? 谢谢你的帮助。

Answer 1:

您需要在您的Gemfile添加“jQuery的UI的轨道”的jQuery的UI插件相关的工作。 请将下面的内容添加到您的Gemfile:

gem 'jquery-ui-rails'

加入这个宝石后,请运行bundle命令:

bundle


Answer 2:

你有3.0.1版本jquery-rails /最后一个版本,现在3.0.1(你可以看到宝石对Gemfile.lock的版本)。

你不把//= require jquery-ui ,因为jquery-ui已经从宝石中删除jquery-rails (3.0.0+)见提交 。 如果你需要jQuery的用户界面,你可以使用jQuery的UI的轨道宝石。


我试图jQuery的动画()和它的作品。 我上的Gemfile轨3.2.13,红宝石1.9.3和宝石“jQuery的轨道”。

下面是我的源代码

<script type="text/javascript">
$(document).ready(function() 
 {
    $('.logo .active-image').animate({
       opacity:1,          //set opacity
       marginTop: "-90px", //move the image 'up' 90px
       }, 5000);           //animate over 5 secs
 });
</script>

<div class="logo">
     <%= image_tag("asus_2.jpg", :class => 'active-image', :height => '100', :width => '123') %>
</div>

我觉得你的jQuery函数存在错误。 您应该检查控制台上的浏览器(检查元素>控制台),你可以看到错误日志。 你可以在你的问题发送错误。



Answer 3:

OK,终于找到了解决办法:

事实上,这是不够的,只是添加gem 'jquery-ui-rails'你的Gemfile。 您还需要在此行中application.js

//= require jquery.ui.all

更多信息可以发现在这里 。

谢谢大家的帮助!



文章来源: How to get jquery animate to work in Rails 3.2.8?