隐藏后的jQuery slideDown()和5秒后的slideUp

隐藏后的jQuery slideDown()和5秒后的slideUp,jquery,Jquery,如何使div#eFileStatus和#sFileStatus向下滑动,然后等待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) {

如何使div#eFileStatus和#sFileStatus向下滑动,然后等待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);
    }
}

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

好的,我找到了解决方案,正如您所看到的,我将slideDown放在ajax函数中,以便它在尝试向下滑动之前等待创建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");
    }
}
函数更改共享(addr)
{
var conf=confirm(“更改共享url将导致无法访问以前的url\n是否确定?”);
如果(conf==true)
{   
//ajax请求更改共享url,在包含状态消息的#键之后创建div
$.post(“/var/jq/ajaxrequest.php”,{changeShare:addr},
功能(数据){
$('#key')。在(''+data.returnValue[1]+'')之后;
//使用新的共享url重新加载#键中的数据
$(“#键”).load(window.location.pathname+“#键>*”);
//滑动状态消息div
$(“#eFileStatus,#sFileStatus”).hide().slideDown().delay(5000.slideUp();
}“json”);
}
}

为什么需要在此处隐藏()?是否检查了浏览器控制台中的错误?您的代码应该可以正常工作:尽管更好的方法是使用
delay()
@eicto,但您需要隐藏元素,因为
slideDown()
动画不会对可见对象起作用elements@koala_dev更适合您的方法::)@user1869566单击顶部菜单上的“运行”按钮
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");
    }
}