jQuery backgroundColor 动画怪异

标签 jquery css jquery-animate background-color

我有下面的 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/

相关文章:

html - 为什么我的 css 网格中的最后一行元素移位了?

jQuery - 动画时调用函数

jQuery 动画 : fadeIn() hidden div, 不显示内容

javascript - 错误率: jquery file upload on submit form button

c# - 如何将对象序列化为 json 并将其发送到 Web 服务?

javascript - jQuery 选择器的速度似乎是错误的我的代码

jquery - 如何在保持绝对定位的同时为依赖于其他元素的文本设置动画

javascript - 单击更改按钮颜色

javascript - JQuery UI 对话框 - 更改标题颜色仅部分有效

css - PostCSS 和 Webpack 配置