2013-05-14 26 views
0

我發現改變asp.net菜單項的不透明度javascript代碼,動畫asp.net菜單使用javascript

$(function() { 
     $("ul.level1 li").hover(function() { 
      $(this).stop().animate({ opacity: 0.7}, "slow"); 
     }, function() { 
      $(this).stop().animate({ opacity: 1}, "slow"); 
     }); 
    }); 

但我並不想改變透明度!
如果我想通過以下功能更改項目的背景顏色,我該怎麼辦?

回答

1
$(function() { 
    $("ul.level1 li").hover(function() { 
     $(this).stop().animate({ backgroundColor: red}, "slow"); 
    }, function() { 
     $(this).stop().animate({ backgroundColor: blue}, "slow"); 
    }); 
}); 

您還需要this

更好的方法是使用簡單的CSS transition有:hover僞選擇。

更新

正如我所說的沒有在jQuery的背景顏色動畫沒有原生支持。如果你想用javascript來做,你需要包含這個插件。

不過,看到它是多麼容易的CSS,使其here

+0

'背景色:'不工作:| – zey 2013-05-14 12:00:51

+0

它不是'background-color',使用'backgroundColor'(camel case!)在JQuery中使用時,css語法略有不同...請看這裏http://learn.shayhowe.com/advanced-html-css/jquery下'操縱',然後'風格操作':) – Stuart 2013-05-14 14:30:18

+0

@Slytael,爲您的css示例+1轉換:所有2s; -webkit轉換:所有2s;',它的工作很棒:) – zey 2013-05-15 03:49:23