Fade in background color using jQuery?

后端 未结 3 961
别那么骄傲
别那么骄傲 2020-12-21 05:03

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?

3条回答
  •  不知归路
    2020-12-21 05:45

    You need to use either jQuery UI libarary or jQuery Colors to enable animation of colors

    $('div').hover(function () {
        $(this).stop(true, true).animate({
            backgroundColor: 'black'
        })
    }, function () {
         $(this).stop(true, true).animate({
            backgroundColor: 'white'
        })
    })
    

    Demo: Fiddle

提交回复
热议问题