使用jQuery淡化背景颜色?

use*_*400 4 jquery

我想拍摄一个div,让背景在mouseenter上淡化成白色,然后在mouseout上淡出黑色.关于如何在jQuery中执行此操作的任何想法?

Sob*_*ine 10

与JQuery .hover()

  $("div" ).hover(
  function() {
     $(this).animate({backgroundColor: "#fff"}, 'slow');
  }, function() {
    $(this).animate({backgroundColor:"#000"},'slow');
  });
Run Code Online (Sandbox Code Playgroud)

与JQuery .mouseover()

$("div")
  .mouseover(function() {
    $(this).animate({backgroundColor: "#fff"}, 'slow');
  })
  .mouseout(function() {
    $(this).animate({backgroundColor:"#000"},'slow');
  });
Run Code Online (Sandbox Code Playgroud)

请注意,您必须使用jquery-color(用于动画颜色).https://github.com/jquery/jquery-color/