jQuery:使用delay()和prepend()

发布于 2024-09-09 08:21:45 字数 395 浏览 12 评论 0原文

在下面的代码中,最后一行不能按照我的方式工作:

$('button.goal').click(function () {
 $('div.scorer_away').animate({
  width: 'hide',
  opacy: 'hide'
  }, 'slow')
 .delay(2500)
 .animate({
  width: 'show',
  opacy: 'show'
  }, 'slow');
 $('span.scorer_away').delay(3000).prepend('<img src="chofbauer.png" alt="" />');

我怎样才能让它工作,prepend()函数在3秒后添加新图像(因为2.5秒后,img在容器中前置)被隐藏)?

In the following code the last line doesn't work in my way:

$('button.goal').click(function () {
 $('div.scorer_away').animate({
  width: 'hide',
  opacy: 'hide'
  }, 'slow')
 .delay(2500)
 .animate({
  width: 'show',
  opacy: 'show'
  }, 'slow');
 $('span.scorer_away').delay(3000).prepend('<img src="chofbauer.png" alt="" />');

How can I make it work, that the prepend()-function adds the new image AFTER 3 sec (because after 2,5 sec the container, where the img prepends is hidden)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

糖粟与秋泊 2024-09-16 08:21:45

.delay() 仅适用于 jQuery fx 方法.prepend() 不是其中之一。

您可以解决它,就像

$('span.scorer_away').delay(3000).show(1, function(){
    $(this).prepend('<img src="chofbauer.png" alt="" />');
});

实际上您必须创建自己的 .queue() 以获得“干净” “ 解决方案。

完成该任务的另一种方法是使用 JavaScript 原生 setTimeout()

setTimeout(function(){
   $('span.scorer_away').prepend('<img src="chofbauer.png" alt="" />');
}, 3000);

.delay() only works with jQuery fx methods. .prepend() is not one of those.

You can workaround it like

$('span.scorer_away').delay(3000).show(1, function(){
    $(this).prepend('<img src="chofbauer.png" alt="" />');
});

Actually you would have to create your own .queue() for a "clean" solution.

Another way to accomplish that task is to use javascripts native setTimeout().

setTimeout(function(){
   $('span.scorer_away').prepend('<img src="chofbauer.png" alt="" />');
}, 3000);
埋葬我深情 2024-09-16 08:21:45

您可以尝试使用 setTimeout

function myfunc() { $('span.scorer_away').prepend('<img...>') };   
setTimeout( myfunc, 3000 );

You could try using setTimeout:

function myfunc() { $('span.scorer_away').prepend('<img...>') };   
setTimeout( myfunc, 3000 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文