Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade in background color using jQuery?

Tags:

jquery

I would like to take a div and have the background fade to white on mouseenter and fade back out to black on mouseout. Any ideas on how to do this in jQuery?

like image 317
user2865400 Avatar asked Dec 16 '22 05:12

user2865400


1 Answers

with JQuery .hover()

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

with JQuery .mouseover()

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

Note you have to use jquery-color (for animating colors). https://github.com/jquery/jquery-color/

like image 185
Sobin Augustine Avatar answered Jan 10 '23 06:01

Sobin Augustine