关于 jQuery 中 Animate 函数的困惑
假设我的页面中有一个框:
<div id="test" style="width:200px; height:200px; background:yellow">
this is a test
</div>
我只在页面中包含“jquery-1.6.2.min.js”,
然后我想更改字体大小,所以我使用
$('#test').animate({ fontSize: "10em"}, "slow");
然后我想更改背景颜色 我写:
$('#test').animate({ 'background-color': '#000000' }, "slow");
但在我包含“jquery-ui-1.8.5.custom.min.js”之前它不起作用。
我认为原来的“jquery-1.6.2.min.js”文件已经包含所有动画功能, fontsize和background color都是css属性,但原来只能支持 字体大小改变?为什么?
我的问题是,我认为包“jquery-ui-1.8.5.custom.min.js”仅用于 UI或者其他一些东西。两者都用于 css 属性更改。
Suppose I have a box in my page:
<div id="test" style="width:200px; height:200px; background:yellow">
this is a test
</div>
I just include "jquery-1.6.2.min.js" in my page
then I want change the font size, so I use
$('#test').animate({ fontSize: "10em"}, "slow");
then I want change the background-color
of the "test" box
I write:
$('#test').animate({ 'background-color': '#000000' }, "slow");
but until I include "jquery-ui-1.8.5.custom.min.js" it doesn't work.
I think the orginal "jquery-1.6.2.min.js" file already include the all animate function,
fontsize and background color are both css attributes,but the original could only support
fontsize change? Why?
My question is that I think the package "jquery-ui-1.8.5.custom.min.js" is just used for
UI or some other things. Both for css attribute changing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读
.animate
的 jQuery 文档:如果您想为
background-color
等属性设置动画,则必须使用 jQuery UI (或其他一些插件),正如您已经注意到的那样。请注意,jQuery UI 站点提供了自定义下载功能,因此如果您不想包含所有小部件,则可以仅选择核心库。Read the jQuery docs for
.animate
:If you want to animate properties like
background-color
you will have to use jQuery UI (or some other plugin) as you have already noticed. Note that the jQuery UI site provides a customised download feature, so if you don't want to include all the widgets, you can select just the core library.jQuery 本身不支持颜色动画。 jQuery UI 可以。曾经有一个单独的颜色插件,但现在似乎已被吸收到 UI 中。
编辑:这是原始插件,您也许可以在没有 UI 的情况下使其工作:
jQuery doesn't natively support animation of colours. jQuery UI does. There used to be a separate colour plugin, but that seems to have been absorbed into UI now.
Edit: Here's the original plugin though, you may be able to get it working without UI: http://plugins.jquery.com/files/jquery.color.js.txt