javascript - Animate Background Color Opacity of a List from brighter to dim - jQuery
问题描述
I'm trying to make my :
- notification list highlighted
- animate background color opacity from brighter to dim (from .8 --> .3) in 1 second.
- blink text 3 times.
I did these :
Please Note:
hexToRgb(faHexColor, opacity=.5 ) = rgba(255,193,7,0.5)
I kept getting
Uncaught TypeError: Cannot read property '0' of undefined
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.
解决方案
所有动画属性都应动画为单个数值,除非以下说明;大多数非数字属性无法使用基本的 jQuery 功能进行动画处理(例如,
width
、height
或left
可以动画但background-color
不能,除非使用 jQuery.Color 插件)。
最好添加 jQuery UI 库以使用动画更改背景颜色。
jQuery UI 捆绑了 jQuery Color 插件,这些插件提供了颜色动画以及许多用于处理颜色的实用功能。
$(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>
推荐阅读
- .htaccess - 为什么这个简单的 RewriteRule 不再起作用,为什么谷歌一直看到它?
- angular - Heroku 审查应用程序寻找 app.development.json 而不是生产
- android - 活动和服务功能有时会并行运行吗?
- java - 如何从使用 Selenium Java 的下拉框中的用户输入的自动完成中提取城市列表
- git - 如何将现有的 Web 应用程序从 pythonanywhere 克隆到 github/local
- mongodb - MongoDb Stitch中的角色权限按功能插入新文档
- c# - 我需要帮助编写一个通过目录、显示文件并说明有多少和哪些扩展名的程序
- angular - 如何使用 Angular 7 从热敏打印机打印 POS 备忘录
- python-3.x - 无法在 Python 中两次为链表显示相同的输出
- java - Android BottomNavigationView 应用程序崩溃,Android Studio - Java