简体   繁体   English

动画列表的背景颜色不透明度从亮到暗 - jQuery

[英]Animate Background Color Opacity of a List from brighter to dim - jQuery

I'm trying to make my:我正在尝试使我的:

  1. notification list highlighted突出显示的通知列表
  2. animate background color opacity from brighter to dim (from.8 -->.3) in 1 second.在 1 秒内将背景颜色的不透明度从更亮变为暗(从.8 -->.3)。
  3. blink text 3 times.闪烁文字 3 次。

I did these:我做了这些:

Please Note:请注意:

hexToRgb(faHexColor, opacity=.5 ) = rgba(255,193,7,0.5) hexToRgb(faHexColor, opacity=.5) = rgba(255,193,7,0.5)

I kept getting我不断得到

Uncaught TypeError: Cannot read property '0' of undefined未捕获的类型错误:无法读取未定义的属性“0”

If I did these:如果我做了这些:

    $('ul.nfTable').find('.operationalEventText').first()
    .css({ 'background-color': hexToRgb(faHexColor, opacity =.8 ) })
    .css({ 'background-color': hexToRgb(faHexColor, opacity =.3 ) })
    .animate({ border: '1px solid ' + hexToRgb(faHexColor, opacity =.3 ) }, 1000)
    .animate({ color: faHexColor }, 300).animate({ color: "white" }, 300)
    .animate({ color: faHexColor }, 300).animate({ color: "white" }, 300)
    .animate({ color: faHexColor }, 300).animate({ color: "white" }, 300);


    $('ul.nfTable').find('.operationalEventText').first().animate({'background-color': '#abcdef',
        'opacity': 0.3}, 100);

It's working, but my console, went crazy.它工作正常,但我的控制台发疯了。

All animated properties should be animated to a single numeric value, except as noted below;所有动画属性都应动画为单个数值,除非以下说明; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width , height , or left can be animated but background-color cannot be, unless the jQuery.Color plugin is used).大多数非数字属性无法使用基本的 jQuery 功能进行动画处理(例如,可以对widthheightleft进行动画处理,但background-color不能,除非使用了 jQuery.Color 插件)。

Best to add the jQuery UI library to make changes to Background Color with Animation.最好添加 jQuery UI 库以使用 Animation 更改背景颜色。

jQuery UI bundles the jQuery Color plugins which provides color animations as well as many utility functions for working with colors. jQuery UI 捆绑了 jQuery 颜色插件,它提供了彩色动画以及许多与 colors 一起使用的实用功能。

 $(function() { $(".box").click(function() { $(".box").animate({ backgroundColor: "rgba(255, 193, 7, 1.0)" }, 1000, function() { console.log("Animation completed."); }); }); });
 .box { width: 100px; height: 100px; background-color: rgba(0, 0, 0, 0.5); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div class="box"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM