2013-10-18 47 views

回答

10

与jQuery .hover()

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

与jQuery .mouseover()

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

注意你必须使用jQuery的颜色(动画颜色)。 https://github.com/jquery/jquery-color/

2

您需要为使用jQuery UI libararyjQuery Colors,使颜色

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

演示动画制作:Fiddle

+0

@nrsharma固定....用于测试目的jQuery用户界面移除 –

0

OP要求的jQuery。对于那些试图徒手没有jQuery的:

<div id="x" style="background-color:rgb(255,255,105)">hello world</div> 
<script type="text/javascript"> 
    var unBlue=100; 
    var gEvent=setInterval("toWhite();", 100); 
    function toWhite(){ 
     if(unBlue<255) document.getElementById("x").style.backgroundColor="rgb(255,255,"+unBlue+")"; 
     else clearInterval(gEvent); 
     unBlue+=10; 
    } 
</script>