0
我正在使用jQuery爲懸停上的導航按鈕提供顏色更改動畫。我有.menu-horizontal
和.menu-vertical
。但由於某種原因,動畫功能與.menu-horizontal
配合良好,但不適用於.menu-vertical
。jQuery動畫問題
垂直菜單的顏色不會改變。
<script type="text/ecmascript">
$(document).ready(function() {
$(".menu-horizontal ul li a").hover(function() {
$(this).stop().animate({ height: "31px", backgroundColor: "#3185b7" }, 600);
}, function() {
$(this).stop().animate({ height: "31px", backgroundColor: "#4fb3d3" }, 600);
});
$(".menu-vertical ul li a").hover(function() {
$(this).stop().animate({ height: "31px", backgroundColor: "#3185b7" }, 600);
}, function() {
$(this).stop().animate({ height: "31px", backgroundColor: "#4fb3d3" }, 600);
});
});
</script>
這不會解決您的問題,但是您是否意識到您可以將代碼縮減一半?你不需要寫出兩次代碼,你可以在兩個選擇器中放置:'$(「。menu-horizontal ul li a,.menu-vertical ul li a」)。hover(function(){' – tw16