简体   繁体   English

如何使jquery动画在Rails 3.2.8中工作?

[英]How to get jquery animate to work in Rails 3.2.8?

I am using jQuery's animate() method in my Rails application. 我在Rails应用程序中使用jQuery的animate()方法。

However, I can't get it to work. 但是,我无法使其正常工作。

This is my application.js file: 这是我的application.js文件:

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

I tried adding //= require jquery-ui in there but it is causing my application to crash: 我尝试在其中添加//= require jquery-ui ,但这导致我的应用程序崩溃:

couldn't find file 'jquery-ui'

Can anybody tell me what I am missing? 谁能告诉我我想念的东西吗? Thanks for any help. 谢谢你的帮助。

You need to add 'jquery-ui-rails' in your Gemfile for jquery-ui related plugins to work. 您需要在Gemfile中添加“ jquery-ui-rails”,jquery-ui相关的插件才能正常工作。 Please add the following line to your Gemfile: 请将以下行添加到您的Gemfile中:

gem 'jquery-ui-rails'

After adding this gem, please run bundle command: 添加此gem后,请运行bundle命令:

bundle

You have version 3.0.1 of jquery-rails / last version now 3.0.1 (you can see version of gem on Gemfile.Lock). 您拥有3.0.1版的jquery-rails /现在是3.0.1版(您可以在Gemfile.Lock上看到gem的版本)。

You don't put //= require jquery-ui because jquery-ui has been remove from gem jquery-rails (3.0.0+) see commit . 您不放//= require jquery-ui因为jquery-ui已从gem jquery-rails (3.0.0+)中删除,请参阅commit If you need jquery-ui, you could use jquery-ui-rails gem. 如果需要jquery-ui,则可以使用jquery-ui-rails gem。


I tried jquery animate() and it's works. 我尝试了jQuery animate(),它的工作原理。 I'm on rails 3.2.13, ruby 1.9.3 and gem 'jquery-rails' on Gemfile. 我在Gemfile上的Rails 3.2.13,ruby 1.9.3和gem'jquery-rails'上。

Here's my source code 这是我的源代码

<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>

I think error existing on your jquery function. 我认为您的jquery函数上存在错误。 You should check console on your browser (inspect element > console) and you can see error log. 您应该在浏览器上检查控制台(检查元素>控制台),然后可以看到错误日志。 You could post error on your question. 您可以在问题中发布错误。

OK, finally found the solution: OK,终于找到了解决方案:

In fact, it's not enough to just add gem 'jquery-ui-rails' to your gemfile. 实际上,仅将gem'jquery gem 'jquery-ui-rails'到您的gemfile中是不够的。 You also need this line in application.js : 您还需要在application.js以下行:

//= require jquery.ui.all

More info can be found here . 更多信息可以在这里找到。

Thanks everybody for your help! 谢谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM