Jquery 动画后台代码不起作用!
看到我有一个 jquery 代码,我认为它应该可以工作,但仍然无法工作!所以请帮助我。输入具有原始背景颜色 #fff
,我希望在聚焦该输入时,背景颜色应更改为具有淡入淡出效果的 #789
。这是我制作的代码。
$('input.login_reg_input').focus(function () {
$(this).animate({
backgroundColor:fadeColor
}, 250, 'linear', function() { });
});
我在stackoverflow上搜索过,没有找到好的解决方案。所以请帮我解决这个问题。
提前致谢!
See I have a jquery code which I thought that it should work but still it's not working! So please can help me out. Th input have original background color #fff
and I want that on focusing that input the background color should change into #789
with a fade effect. Here is the code that I have made.
$('input.login_reg_input').focus(function () {
$(this).animate({
backgroundColor:fadeColor
}, 250, 'linear', function() { });
});
I have search through the stackoverflow and had not found a good solution. So please help me out with this.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
仅使用 jQuery 库,您无法对背景颜色进行动画处理。但您可以使用其上的 jQuery UI 为其添加动画效果。
所以这工作得很好
几年后,这里有更好的替代方案:
使用 CSS3
jsFiddle
仅使用 jQuery(没有 jQuery UI)
jsFiddle
With just the jQuery lib you cannot animate the background color. But you can animate it with the jQuery UI on top of it.
So this works fine
Some years later, here are better alternatives:
Using CSS3
jsFiddle
Using only jQuery (without jQuery UI)
jsFiddle
我在 http://api.jquery.com/animate/ 上找到了这段:
它说背景颜色不能动画。
I found this paragraph on http://api.jquery.com/animate/:
It says that background-color cannot be animated.
从 jQuery 文档的 animate 页面:
“所有动画属性都应该动画化单个数值,除非如下所述;大多数非数值属性无法使用基本 jQuery 功能进行动画处理(例如,宽度、高度或左侧可以进行动画处理,但背景颜色不能进行处理。)。除非另有说明,否则可以在适用的情况下指定单位 em 和 %。”
From the animate page on jQuery docs:
"All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality. (For example, width, height, or left can be animated but background-color cannot be.) Property values are treated as a number of pixels unless otherwise specified. The units em and % can be specified where applicable."
除了正确引用
animate()
文档的其他答案之外,可以使用 颜色插件< /a>,或使用 jQuery UI。JS Fiddle 使用演示。
In addition to the other answers, which correctly cite the
animate()
docs, it is possible to animate thebackground-color
with either the color plug-in, or using the jQuery UI.JS Fiddle usage demo.
查看此链接
此处:
看起来您将需要 jQuery 颜色插件
我尝试测试您的代码,它可以在本地保存颜色插件:
Check out this link
here:
It looks as though you will need the jQuery color plugin
I tried with a test of your code and it works having saved the color plugin locally:
jQuery 不支持颜色动画,因此您需要颜色插件或 jQuery UI。
您只能在插件上使用此属性,
这是库
http://plugins.jquery.com/files/jquery.colorBlend.js_6.txt
jQuery doesn't support color animations so you'll need the color plugin or, jQuery UI.
you can use this properties only on the plugins
this is the library
http://plugins.jquery.com/files/jquery.colorBlend.js_6.txt