jQuery - Wait till end of SlideUp()

懵懂的女人 提交于 2019-12-29 07:22:08

问题


How can I wait till the end of the jQuery function slideUp() before continuing the script?

<script type="text/javascript">
$(document).ready(function() {
    $("div[class=item]").click(function() {
        var id = $(this).attr("id");
        $("#content").slideUp();
        switch(id) {
            // Applications
            case "rampro":
                $("#content").css("text-align", "left");
                $("#content").load("inc/pages/rampro.html");
                $("#content").slideDown();
                break
            case "diskman":
                $("#content").css("text-align", "left");
                $("#content").load("inc/pages/diskman.html");
                break
            case "iconmap":
                $("#content").css("text-align", "left");
                $("#content").load("inc/pages/iconmap.html");
                break
            // Websites
            case "benoks":
                $("#content").css("text-align", "left");
                $("#content").load("inc/pages/benoks.html");
                break
            case "linkbase":
                $("#content").css("text-align", "left");
                $("#content").load("inc/pages/linkbase.html");
                break
            case "jamesbrooks":
                $("#content").css("text-align", "left");
                $("#content").load("inc/pages/jamesbrooks.html");
                break
            default:
                $("#content").css("text-align","center");
                $("#content").html("<h1>something went wrong, try again!</h1>");
        }
        return false;
    });
});


回答1:


Use the callback mechanism and have your code run in the callback.

$('#something').slideUp('fast', function() {
   ... stuff to do after the slide is complete...
});



回答2:


slideUp() takes two arguments. If you pass a function as the second argument, it'll be called when the animation is complete.

http://docs.jquery.com/Effects/slideUp



来源:https://stackoverflow.com/questions/1084392/jquery-wait-till-end-of-slideup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!