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