隐藏后滑动jQuery slideDown(),5秒后滑动

时间:2013-09-23 23:39:05

标签: jquery

我如何制作div #eFileStatus和#sFileStatus slideDown然后等待5秒并滑动,这是我的功能,当前有效,并在5秒后滑动。

function changeShare(addr)
{
    var conf = confirm("Changing the share url will cause the previous URL to not be accessible\nAre you sure?");
    if(conf == true)
    {   
        // ajax request to change share url, create div after #key containing status message
        $.post("/var/jq/ajaxrequest.php", { changeShare: addr },
        function(data){
            $('#key').after('<div id="'+data.returnValue[0]+'FileStatus">'+data.returnValue[1]+'</div>');
        }, "json");
        // reload data in #key with new share url
        $("#key").load(window.location.pathname+" #key > *");
        // slideup the status message div
        setTimeout(function(){
            $('#eFileStatus').slideUp();
            $('#sFileStatus').slideUp();        
        }, 5000);
    }
}

我试过了:

        $("#eFileStatus, #sFileStatus").hide().slideDown(function(){
            setTimeout(function(){
                $('#eFileStatus').slideUp();
                $('#sFileStatus').slideUp();        
            }, 5000);
        });

但这不会下滑,也会停止向上滑动。

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案,因为你可以看到我将slideDown放在ajax函数中,所以它等待在尝试slideDown之前创建div。

function changeShare(addr)
{
    var conf = confirm("Changing the share url will cause the previous URL to not be accessible\nAre you sure?");
    if(conf == true)
    {   
        // ajax request to change share url, create div after #key containing status message
        $.post("/var/jq/ajaxrequest.php", { changeShare: addr },
        function(data){
            $('#key').after('<div id="'+data.returnValue[0]+'FileStatus">'+data.returnValue[1]+'</div>');
            // reload data in #key with new share url
            $("#key").load(window.location.pathname+" #key > *");
            // slideup the status message div
            $("#eFileStatus, #sFileStatus").hide().slideDown().delay(5000).slideUp();
        }, "json");
    }
}