jQuery动画问题

标签 jquery html css

我正在使用 jQuery 为我的导航按钮提供悬停时的颜色变化动画。

我有 .menu-horizo​​ntal.menu-vertical。但出于某种原因,动画功能适用于 .menu-horizo​​ntal 但不适用于 .menu-vertical

垂直菜单的颜色不变。

<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>

最佳答案

您不能单独使用 jQuery 为 background-color 设置动画。

(For example, width, height, or left can be animated but background-color cannot be.)

来源:http://api.jquery.com/animate/#animation-properties

选项 1:首先使用 .css() 设置 background-color,然后设置高度动画。

选项 2:使用 plugin促进 background-color 动画。

关于jQuery动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7115843/

相关文章:

html - float block 崩溃

jquery - 将 Css 应用于 jQuery ui datepicker 中的日期链接

javascript - 尝试显示和隐藏 div 以实现排序效果

javascript - 有没有一种方法可以使用 classList 在一条指令中添加/删除多个类?

css - 替换 <font color : red>text </font> in css and HTML5 的最佳方法是什么

css - 在右上角添加登录

html - 垂直对齐 <a> 标签内的元素

javascript - href 标签的 click 事件(动态创建)

javascript - 在事件委托(delegate)中传递 jQuery 对象

html - CSS 下拉菜单 'hit box'