2012-05-19 99 views
0

我有li元素:如何动画颜色?

<ul> 
    <li><a href="">test 1</a></li> 
    <li><a href="">test 2</a></li> 
</ul> 

,我想,一个新的颜色来自底部动画悬停颜色。

怎么办?

+0

刚上文字或背景? – mrzmyr

+0

你能把我们连接到一个例子吗? – sirmdawg

+2

[你有什么尝试?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – j08691

回答

1

您需要使用此jQuery PlugIn才能为颜色提供animate()功能!

使用示例(从GitHub页面复制!)

<!DOCTYPE html> 
<html> 
<head> 
    <style> 
    div { 
     background-color:#bada55; 
     width:100px; 
     border:1px solid green; 
    } 
    </style> 
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script> 
    <script src="jquery.color.min.js"></script> 
</head> 
<body> 
    <button id="go">Simple</button> 
    <button id="sat">Desaturate</button> 
    <div id="block">Hello!</div> 
    <script> 
    $("#go").click(function(){ 
     $("#block").animate({ 
     backgroundColor: "#abcdef" 
     }, 1500); 
    }); 

    $("#sat").click(function(){ 
     $("#block").animate({ 
     backgroundColor: $.Color({ saturation: 0 }) 
     }, 1500); 
    }); 
    </script> 
</body> 
</html> 
+0

我知道如何改变颜色,但我不知道如何升起 – Nips

+0

没关系,那么它是http://stackoverflow.com/questions/6763428/background-color-slide-down或http:// stackoverflow .com/questions/3633115/background-color-property-slide-up – thomas

+0

ok :)但是ul-> li是由wordpress导航菜单自动生成的。修改代码的能力不大 – Nips