jQuery的:两个动画()上点击功能。延时()的问题? [英] jquery: two animate() functions on one click. delay() problem?

查看:191
本文介绍了jQuery的:两个动画()上点击功能。延时()的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计们,
我有一个奇怪的和可能很少的问题。

hey guys, i have a weird and probably rare problem.

点击一个链接时,下列函数被调用。

The following function is called when a link is clicked.

$(selector).delay(500).animate({ backgroundColor: '#ccc' }, 300).delay(1000).animate({ backgroundColor: '#333' }, 300);

它所做的是,它亮点为1秒点击的项目。

All it does is, it "highlights" the clicked item for 1sec.

在相同的链接我所说的不同的功能在我的code进一步下跌:

On the same link I call a different function further down in my code:

$(selector).animate({'height':'450px' }, 'fast', function() {
    console.log('has a delay')
})

会发生什么情况是,第二动画不会立即触发而是等待第一个完成(或类似的东西)。

What happens is, that the second animation does not trigger instantly but waits for the first to finish (or something like that).

所以,高度值的动画有怎样的一个超时。

So the animation of the 'height' value has kind of a timeout.

任何想法,我怎么能解决呢?

Any idea how I could solve that?

更多信息:第一个函数调用在包含#hash所有链接。因此,这两个功能必须是不同的 - 我无法将它们合二为一。如果一个特定的链路(在它一个#hash)被点击第二函数只是调用。所以,只为这一个环节都功能被触发。

推荐答案

动画默认情况下排队。如果你不想让你的动画排队就可以在 .animate选项指定它(属性,选项)

Animations are queued by default. If you do not want your animations queued you can specify it in the options for .animate( properties, options )

队列:一个布尔指示是否
  放置在效果的动画
  队列。如果为false,动画将
  立即开始。

queue: A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately.

把与你的榜样,它可能是这个样子:

Putting that with your example, it might look something like this:

$(selector).animate({
    'height': '450px'
     },{
    duration: 'fast',
    complete: function () {
        console.log('has a delay')
    },
    queue: false
});

code例子显示在的jsfiddle ,队列行为

Code example showing the queue behavior on jsfiddle.

这篇关于jQuery的:两个动画()上点击功能。延时()的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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