jquery 延迟执行

$(function(){
    var $inputs = $('input[type=button]')
        .delay(500)
        .queue(function(){$(this).hide().dequeue();})
        .delay(1500)
        .queue(function(){$(this).show();});
});
以上代码让页面中的按钮在页面加载后500毫秒隐藏,然后再过1500毫秒显示出来。  

$(function(){
    var $inputs = $('input[type=button]')
        .delay(500)
        .queue(function(){$(this).hide().dequeue();})
        .delay(1500)
        .show(1);
        //.queue(function(){$(this).show();});
});
以上代码效果与前面的代码相同。

$(function(){
    var $inputs = $('input[type=button]')
        .delay(500)
        .queue(function(){$(this).hide();})
        .delay(1500)
        .show(1);
        //.queue(function(){$(this).show();});
});
以上代码同样只隐藏,不会再显示,相比代码2,queue里的代码没有调dequeue,由此可知,queue执行完后,也中止了动画队列的继续执行,需要调用dequeue使其执行下去(这里queue里的hide()不是一个动画,而将当前对象的动画放在queue里执行也会有问题)。

$(function(){
    var $inputs = $('input[type=button]')
        .delay(500)
        .queue(function(){$(this).hide().dequeue();})
        .delay(1500)
        .show();
        //.show(1);
});
以上代码只隐藏,而不会再显示!!这里show不再指定显示动画时长,则show方法不再是一个动画。由此可知,dequeue只能使得动画队列中的后续方法执行下去,不能使非动画队列中的jquery方法继续执行!



原文地址:https://www.cnblogs.com/wyang0126/p/5039944.html