Fading colors with jquery?

前端 未结 3 1221
余生分开走
余生分开走 2021-01-28 10:08

I have a regular color change using jquery, but I\'d like to have it so it has a smooth color change. At the moment, the code changes the color of a link on hover and then remov

相关标签:
3条回答
  • 2021-01-28 10:35

    If you are looking for "smooth" color change then perhaps you are asking for color animation, check out this thread:

    How do you fade in/out a background color using jquery?

    0 讨论(0)
  • 2021-01-28 10:39

    You'd use .animate(), like this:

    $(document).ready(function() {
      $("#link1,#link2,#link3").hover(function() {
        $(this).stop().animate({ color: "#990000" });
      },function(){
        $(this).stop().animate({ color: "#FFFFFF" });
      }); 
    });
    

    Note though, you need either the color plugin, or jQuery UI included for color animations to work.

    0 讨论(0)
  • 2021-01-28 10:39

    Here's an easy way without using the extra jquery plugin. In fact, this is mostly done with css. Make 2 divs on top of each other and fade the top one. Like so: http://jsfiddle.net/Jny9x/

    0 讨论(0)
提交回复
热议问题