我有下面的 javascript 函数,当一个新文档被添加到列表时,它会闪烁链接的 bg 3 次。
这第一次工作正常,但随后对该函数的调用导致闪烁变得困惑。越叫越怪异的闪烁行为。
我在 IE8 和最新版本的 Chrome 中看到了同样的效果。
var highlightNew = function (control) {
var item = $('li.new-document a.document-link', control);
if (item.length > 0) {
var highlightColor = '#ffa500';
item.stop()
.animate({ backgroundColor: highlightColor }, 'slow')
.animate({ backgroundColor: 'transparent' }, 'slow')
.animate({ backgroundColor: highlightColor }, 'slow')
.animate({ backgroundColor: 'transparent' }, 'slow')
.animate({ backgroundColor: highlightColor }, 'slow')
.animate({ backgroundColor: 'transparent' }, 'slow');
}
}
最佳答案
你有这方面的插件吗?
根据 jQuery 文档,您不能为背景颜色设置动画。 jQuery 推荐为此使用 jQuery.Color 插件。
jQuery 动画文档 - http://api.jquery.com/animate/
jQuery 颜色插件 - https://github.com/jquery/jquery-color
关于jQuery backgroundColor 动画怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13752384/