jQuery:动画文本颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7516407/
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 23:56:59  来源:igfitidea点击:

jQuery: animate text color

jqueryhyperlinkjquery-animate

提问by Mikaelik

i wanna dynamically change the link color within a hover event. I got the following code so far but it doesn′t work. Any suggestions why? In my oppinion it seems to be right...

我想在悬停事件中动态更改链接颜色。到目前为止,我得到了以下代码,但它不起作用。任何建议为什么?在我看来,这似乎是对的......

    $('.fadelink').hover(function(){            
        $(this).animate({
            color: '#333'
        }, 600);            
    },
    function(){
        $(this).animate({
            color: '#999'
        }, 600);          
    });

回答by Arda

You have to add colorsplugin to make it work. That is stripped from core.

您必须添加颜色插件才能使其工作。那是从核心中剥离出来的。

回答by Joakim Johansson

jQuery doesn't support animation of colors, but it can with the color plugin: http://plugins.jquery.com/project/color

jQuery 不支持颜色动画,但它可以使用颜色插件:http: //plugins.jquery.com/project/color

However, there's another route you could take, with CSS3, if you don't mind it not working in some older browsers:

但是,如果您不介意在某些较旧的浏览器中无法使用 CSS3,您还可以采用另一种方法:

.baseClass {
    color:#999; 

    -webkit-transition-property:color; 
    -webkit-transition-duration: 1s, 1s; 
    -webkit-transition-timing-function: linear, ease-in;
}

.baseClass:hover {
    color: #333;
}

回答by Naftali aka Neal

See the answer to this question: jQuery: animate text color for input field?

请参阅此问题的答案:jQuery: animate text color for input field?

You cannotanimate css text color with jQuery.

不能使用 jQuery 为 css 文本颜色设置动画。

回答by Muhammad Usman

You have to use jQuery color pluginto make color animation work.

您必须使用jQuery 颜色插件来制作彩色动画。