首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如果正在进行,则禁用动画

如果正在进行,则禁用动画
EN

Stack Overflow用户
提问于 2011-07-01 03:38:05
回答 3查看 162关注 0票数 0

如果这个脚本已经在动画中,我如何让它禁用动画?

代码语言:javascript
运行
复制
<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>

我真的是jQuery的新手,我通过搜索找到的东西并没有真正的帮助。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-07-01 03:39:33

使用.stop()

代码语言:javascript
运行
复制
    $("#nav").hover(
        function() {
            $("#header-wrapper").stop(true,false).animate({height:140},500);
            $("#dropdown").stop(true,false).animate({height:100},500);
        },
        function() {
            $("#header-wrapper").stop(true,false).animate({height:40},500);
            $("#dropdown").stop(true,false).animate({height:0},500);
        }
    );
票数 3
EN

Stack Overflow用户

发布于 2011-07-01 03:39:44

使用.stop() jQuery函数

代码语言:javascript
运行
复制
$("#dropdown").stop().animate({height:0},500);
票数 2
EN

Stack Overflow用户

发布于 2011-07-01 04:05:31

试试这个:

代码语言:javascript
运行
复制
$("#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());
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6540170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档