我正在尝试淡入表格行的背景颜色,但无法做到正确。单击按钮时将发生淡入。
我尝试了类似的方法:
$("#row_2").fadeIn('slow').css('background', 'gold')
虽然这会将颜色应用到表格行,但它不会淡入,而是立即应用。
我确信这是一件简单的事情,但我找不到答案。我已经浏览过这个网站,但对于这个特定的事情仍然没有运气。
提前致谢
I'm trying to fade in the background colour of a table row, and can't get it right. The fade-in will happen when a button is clicked.
I tried something like:
$("#row_2").fadeIn('slow').css('background', 'gold')
And although this will apply the colour to the table row, it won't fade in, but apply it at once.
I'm sure this is a simple thing, but I can't find an answer to that. I've looked all over in this website, but still no luck for this specific thing.
Thanks in advance
发布评论
评论(4)
纯 jQuery 不具有动画颜色的功能。您必须使用 jQueryUI 或 jQuery 颜色插件。
然后使用 .animate() 函数。
The pure jQuery does not have functionality to animate colors. You have to use jQueryUI or jQuery color plugin.
Then use
.animate()
function.如果您还没有使用Peter Peller 就是正确的选择.com/" rel="nofollow noreferrer">jquery UI,那么至少使用 jQuery 颜色插件。
下面是我编写的代码片段,它在各种浏览器中都取得了成功:
作为替代方案,您可能希望首先将背景着色为其原始颜色,然后将动画设置为新颜色。
要实现这一点,只需将当前的动画块替换为如下内容:
Peter Peller is spot-on, if you're not already employing jquery UI, then at least go with the jQuery color plugin.
Below is a code snippet that I whipped-up which had success across a variety of browsers:
As an alternate, you may want to color the background to its original color first, then animate to the new color.
To make that happen, just replace the current animate block with something like this:
不幸的是,不可能淡入背景颜色(我不知道jquery的最新版本)。但是,您可以使用此插件来实现此目的:
highlightFade
现在由您决定是否使用该插件来实现背景淡入淡出效果:)
Unfortunately it is not possible to fade in the background color (I don't know about the latest release of jquery). However you can use this plugin for that purpose:
highlightFade
Now it's up to you whether you use that plugin or not for just background fading effect :)
jquery 突出显示效果怎么样,如下所示:
您还可以指定突出显示的颜色和持续时间。您可以从 jquery 站点了解更多信息。
What about jquery highlight effect, like this:
Also you can specify color and duration it should be hightlighted. You can learn more from jquery site.