我真的很困惑,因为我试图在 coffeescript 中为 rails 3.1 编写一些 jQuery 教程,但似乎 jquery 的动画功能都不起作用。
例如,这什么都不做:
/assets/javascripts/my_controller.js.coffee
:
$(document).ready ->
$('p:first').fadeIn()
但是,如果我这样做:
$(document).ready ->
alert($('p:first').text())
我确实得到了正确的文本。谁能告诉我这是怎么回事?
谢谢大家,感谢 Trevor 读懂了我的想法。感谢 Benoit 帮助我正确使用该网站。我的最终答案如下。
最佳答案
我仔细研究了一下,发现了这个:(来自 http://api.jquery.com/visible-selector/)
Elements with visibility: hidden or opacity: 0 are considered to be visible, since they still consume space in the layout. During animations that hide an element, the element is considered to be visible until the end of the animation. During animations to show an element, the element is considered to be visible at the start at the animation.
How :visible is calculated was changed in jQuery 1.3.2. The release notes outline the changes in more detail.
因此,使用正确的样式,或者 jQuery 中的切换函数是正确的选择。
关于javascript - Rails 3.1 是否包括整个 jQuery 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7538200/