jQuery:为输入字段设置动画文本颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1354277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:17:00  来源:igfitidea点击:

jQuery: animate text color for input field?

jqueryinputcolorsjquery-animate

提问by John Foster

I've got this really simple piece of code that I thought was the correct way to get jQuery to animate the text color for a given input field.

我有一段非常简单的代码,我认为这是让 jQuery 为给定输入字段设置文本颜色动画的正确方法。

$('input').animate({color: '#f00'}, 500); 

But it won't work. However, I can change the text color:

但它不会工作。但是,我可以更改文本颜色:

$('input').css('color', '#f00'); 

I've tried this in both Safari 4 and Firefox 3.5 with the same (lacking) results. I'd really appreciate any input on this problem as I'm running out of hair... Thanks.

我已经在 Safari 4 和 Firefox 3.5 中尝试过这个,但结果相同(缺乏)。我真的很感激关于这个问题的任何意见,因为我的头发快用完了......谢谢。

回答by John Foster

jQuery doesn't support color animations so you'll need the colorplugin or, jQuery UI. Both allow you to use the syntax you're using for properties like background-color and color.

jQuery 不支持彩色动画,因此您需要颜色插件或jQuery UI。两者都允许您使用用于背景颜色和颜色等属性的语法。

回答by matadur

You can do this without the color plugin. I've answered this question here.

您可以在没有颜色插件的情况下执行此操作。我已经在这里回答了这个问题。

回答by redsquare

To animate color you need the jquery color plugin.

要动画颜色,您需要jquery 颜色插件

回答by n1313

You'll need Color Animations pluginfor this

为此,您需要Color Animations 插件

回答by kaiz.net

Use jQueryUIand your code works as it is.

使用jQueryUI,您的代码将按原样运行。

回答by kaiz.net

I found the color plugin to be extremely flaky from one page load to another, even on a static page with the exact same code..! ColorBlend did the job perfectly time though. http://plugins.jquery.com/files/jquery.colorBlend.js_6.txt

我发现颜色插件从一个页面加载到另一个页面非常不稳定,即使在具有完全相同代码的静态页面上..!不过,ColorBlend 完美地完成了这项工作。 http://plugins.jquery.com/files/jquery.colorBlend.js_6.txt