javascript - 如何使用 .animate 更改文本颜色
问题描述
我想在用新信息更新时闪烁一些文本。为此,我需要一个过渡。因为信息将在 60 秒内全部更新我想使用 jQuery .animate 方法。
由于某种原因,它无法更改文本颜色。保证金和其他东西工作正常。有没有办法改变 textcolor 线性?
$('html').click(function() {
$('div').animate({ color: 'red', 'margin': '200px' }, 700);
});
body {
background: grey;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">My Text</div>
解决方案
您可以通过在单击事件后添加动画类来实现。请检查以下解决方案:
$('html').click(function() {
$('div').addClass('animated');
});
body {
background: grey;
color: #fff;
}
.animated {
margin:200px;
color:red;
transition:all .7s;
}
推荐阅读
- elasticsearch - 直接将日志写入 Logstash 还是通过 filebeat 更好地写入(应用程序性能角度)?
- java - 如何在没有实例变量和泛型的情况下实现方法
- r - R合并两个数据框,删除唯一的患者ID
- oracle - 使用索引表空间添加约束 PK
- javascript - 从 Mysql 数据库生成嵌套的 excel 文件
- .net-core - 如何使用 Identity Server 4 授权码授予类型流程获取授权码
- python-3.x - 如何制作一个停止另一个命令的不和谐 python 命令?
- php - If science value>6 link else if science value<6 different linkhow to do that
- javascript - 如何在 NodeJS 中同步 2 个异步函数?
- r - 在一小时内改变下一个唯一值并扩展和聚合