Javascript 禁用正在进行的动画

Javascript 禁用正在进行的动画,javascript,jquery,animation,Javascript,Jquery,Animation,如果此脚本已设置动画,如何使其禁用动画 <script type="text/javascript"> $(document).ready(function() { $("#nav").hover( function() { $("#header-wrapper").animate({height:140},500); $("#dropdown").animate({hei

如果此脚本已设置动画,如何使其禁用动画

<script type="text/javascript">
    $(document).ready(function() {
        $("#nav").hover(
            function() {
                $("#header-wrapper").animate({height:140},500);
                $("#dropdown").animate({height:100},500);
            },
            function() {
                $("#header-wrapper").animate({height:40},500);
                $("#dropdown").animate({height:0},500);
            }
        );
    });
</script>

$(文档).ready(函数(){
$(“#导航”)。悬停(
函数(){
$(“#标题包装”).animate({height:140},500);
$(“#下拉”).animate({height:100},500);
},
函数(){
$(“#标题包装”).animate({height:40},500);
$(“#下拉”).animate({height:0},500);
}
);
});
我对jQuery非常陌生,我通过搜索找到的东西并没有真正的帮助。

使用

使用

使用.stop()jQuery函数

$("#dropdown").stop().animate({height:0},500);
使用.stop()jQuery函数

$("#dropdown").stop().animate({height:0},500);
试试这个:

$("#nav").hover(function() {
    if (!$("#header-wrapper").is(':animated')) {
        $("#header-wrapper").animate({
            height: 140
        },
        500);
        $("#dropdown").animate({
            height: 100
        },
        500);
    } else {
        $("#header-wrapper").stop(true, false).css('height', $("#header-wrapper").height());
        $("#dropdown").stop(true, false).css('height', $('#dropdown').height());
    }
},
function() {
    if (!$("#header-wrapper").is(':animated')) {
        $("#header-wrapper").animate({
            height: 40
        },
        500);
        $("#dropdown").animate({
            height: 0
        },
        500);
    } else {
        $("#header-wrapper").stop(true, false).css('height', $("#header-wrapper").height());
        $("#dropdown").stop(true, false).css('height', $("#dropdown").height());
    }
});
试试这个:

$("#nav").hover(function() {
    if (!$("#header-wrapper").is(':animated')) {
        $("#header-wrapper").animate({
            height: 140
        },
        500);
        $("#dropdown").animate({
            height: 100
        },
        500);
    } else {
        $("#header-wrapper").stop(true, false).css('height', $("#header-wrapper").height());
        $("#dropdown").stop(true, false).css('height', $('#dropdown').height());
    }
},
function() {
    if (!$("#header-wrapper").is(':animated')) {
        $("#header-wrapper").animate({
            height: 40
        },
        500);
        $("#dropdown").animate({
            height: 0
        },
        500);
    } else {
        $("#header-wrapper").stop(true, false).css('height', $("#header-wrapper").height());
        $("#dropdown").stop(true, false).css('height', $("#dropdown").height());
    }
});

这确实起到了作用,但如果你快速鼠标离开,它现在会从动画状态快速跳转。它实际上应该是
(真,假)
,但如果你快速鼠标离开,它现在会从动画状态快速跳转。它实际上应该是
(真,假)