如何使用 jQuery 更改文本颜色?

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

How can I change the text color with jQuery?

jquerytext

提问by Jorge

When I hover a text with animation definitely I will use jQuery. Is there a code that will change the color, or size?

当我将带有动画的文本悬停时,我肯定会使用 jQuery。是否有可以改变颜色或大小的代码?

回答by Annabelle

Place the following in your jQuery mouseoverevent handler:

将以下内容放在您的 jQuerymouseover事件处理程序中:

$(this).css('color', 'red');

To set both color and size at the same time:

同时设置颜色和大小:

$(this).css({ 'color': 'red', 'font-size': '150%' });

You can set any CSS attribute using the .css()jQuery function.

您可以使用.css()jQuery 函数设置任何 CSS 属性。

回答by Prog Mania

Or you may do the following

或者您可以执行以下操作

$(this).animate({color:'black'},1000);

But you need to download the color plugin from here.

但是你需要从这里下载颜色插件。

回答by Jonah

Nowadays, animating text color is included in the jQuery UI Effects Core. It's pretty small. You can make a custom download here: http://jqueryui.com/download- but you don't actually need anything but the effects core itself (not even the UI core), and it brings with it different easing functions as well.

如今,动画文本颜色已包含在 jQuery UI 效果核心中。它很小。您可以在此处进行自定义下载:http: //jqueryui.com/download- 但实际上除了效果核心本身(甚至不是 UI 核心)之外,您实际上不需要任何东西,并且它还带来了不同的缓动功能。