【发布时间】:2014-07-06 04:19:59
【问题描述】:
我正在尝试制作个人网站,但我遇到了 jQuery 的情况。
.animate 函数的行为很奇怪。
我有这个 CofeeScript 代码,它应该为体验部分右侧的橙色链接设置动画 here
$(".resume_show, .experiences_index, .experiences_show").ready ->
# The above scoping is possible with the awesome pluging jquery-readyselector
$("div.link_txt").rotate -90
$("section.preview").hover (->
$(this).children("a").stop(true).animate width: "40px", 0, "swing"
$(this).children("a").children("img").stop(true).fadeIn 500
$(this).children("a").children("div.link_txt").stop(true).fadeIn 500
return
), ->
$(this).children("a").stop(true).animate width: "5px", 0, "swing"
$(this).children("a").children("img").stop(true).fadeOut 100
$(this).children("a").children("div.link_txt").stop(true).fadeOut 100
return
return
如您所见,我不得不将 duration 修复为 0,因为 jQuery 对此进行了延迟。
我试图在 JSFiddle 上复制/粘贴我的代码,问你为什么我会遇到这种奇怪的行为,但它运行良好:http://jsfiddle.net/8s3Fn/
所以我认为这是我的开发环境的问题:
我在 Ruby On Rails 上进行开发。也许其他 gem 之一不兼容,但是由于默认包含 jQuery,我对此表示怀疑。
这是我的 Gemfile:
source 'https://rubygems.org'
ruby '2.1.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use sqlite3 as the database for Active Record
group :development do
gem 'sqlite3'
end
# Rail administration
gem 'devise'
gem 'activeadmin', github: 'gregbell/active_admin'
# Use SCSS for stylesheets
gem 'sprockets'
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-turbolinks'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
# Markdown support
gem 'redcarpet'
# Sucurity token issue
gem "figaro"
# Bread Crum
gem "crummy", "~> 1.8.0"
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
总之,当我打开 Firefox 控制台并悬停这些部分时,我会收到以下消息:
reflow: 0.18ms
reflow: 0.16ms
reflow: 0.31ms
reflow: 0.16ms
reflow: 0.32ms
reflow: 0.18ms
reflow: 0.18ms
reflow: 0.2ms
我还有其他使用 jQuery 的 .animate 动画的移动部件,一切正常:
- 持续时间确实就是持续时间
- 控制台上没有消息
对于其他运动部件,.animate 在left 或top 上运行
对于奇数,.animate 在width 上运行
你知道我为什么会遇到这个问题吗?
【问题讨论】:
-
你想做什么?它对我有用
-
是的,我知道它正在工作......它不应该因为我将持续时间设置为零(它应该从无处弹出)。我正在尝试使 jQuery 正常工作。我也想改变这个动画的持续时间,但我不能......
-
你用的是什么jquery版本?
-
我使用的是 jQuery 1.11.1
-
好的,我想首先指出几件事,你们不需要传递
swing选项,因为它是默认选项,其次你不需要嵌套你的选择器,比如.children().children看起来很丑,顺便说一句,我刚刚通过将延迟更改为1000来测试你的代码,它在你的网站上对我有用
标签: jquery ruby-on-rails animation coffeescript jquery-animate