回调到.delay() [英] Callback to .delay()

查看:106
本文介绍了回调到.delay()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个$image,我是.fadeIn.fadeOut,然后是.remove.这是我的代码:

I have an $image that I .fadeIn and .fadeOut, and then .remove after .fadeOut completes. This is my code:

$image
   .fadeIn()
   .fadeOut(function() {
      $(this).remove();
   });

我想在.fadeOut之后添加.delay,并且仅在.delay完成后添加.remove $image.我已经尝试过:

I want to add a .delay after .fadeOut, and .remove the $image only once .delay has completed. I have tried:

$image
   .fadeIn()
   .fadeOut()
   .delay(1000, function() {
      $(this).remove();
   });

问题是.delay接受回调函数.我如何.remove图片作为.delay的回调?

The problem is that .delay doest not accept a callback function. How can I .remove the picture as a callback to .delay?

推荐答案

您可以使用 queue()安排您自己的函数在delay()完成后运行的方法:

You can use the queue() method to schedule your own function to run after delay() completes:

$image.fadeIn()
      .fadeOut()
      .delay(1000)
      .queue(function(next) {
          $(this).remove();
          next();
      });

这篇关于回调到.delay()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆