搜索
javascript - js如何实现文字颜色渐变
PHP中文网
PHP中文网 2017-04-10 12:43:22
[JavaScript讨论组]

javascript如何实现鼠标hover链接,链接字体颜色渐变?

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(3)
天蓬老师

修正:
第一次没有仔细读官方文档,jQuery 原生不支持 color 的 animate,因为 color 的值不是数字。谢谢 @airyland 及 @冰剑 的纠正。

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). Property values are treated as a number of pixels unless otherwise specified. The units em and % can be specified where applicable.

让 animate 支持 color,有以下三种方法:
1. 引入 jQuery UI
2. 引入 jQuery color
3. 引入 jQuery color animation

可以使用 jQuery 提供的 animate 方法,具体参考:http://api.jquery.com/animate/

比如本页面上作者名链接,简单示例:

$('.post-author a').on('hover', function(){
  $(this).animate({ color: '#ffffff'}, 5000)
})
阿神

如果浏览器支持,可以用CSS3中的transition,而不用javascript实现,只需要简单的几条css声明。

天蓬老师

答案不靠谱

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号