Home  >  Q&A  >  body text

javascript - js如何实现文字颜色渐变

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

PHP中文网PHP中文网2748 days ago1145

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-10 12:45:22

    修正:
    第一次没有仔细读官方文档,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)
    })

    reply
    0
  • 阿神

    阿神2017-04-10 12:45:22

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

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-10 12:45:22

    答案不靠谱

    reply
    0
  • Cancelreply