同时运行两个jQuery函数 [英] Run two jQuery functions at the same time
问题描述
我正在使用jQuery向下滑动某些内容并将其他内容淡出,但在测试时,我注意到滑动发生后褪色显得太长。
换句话说,它有足够的延迟,这是显而易见的。
I am using jQuery to slide something down and fade something else out, but in testing it, I've noticed that the fading appears too long after the sliding happens. In other words, there is enough of a lag that it is noticeable.
为了让自己清楚,这两个项目,我滑动一个和褪色另一个是不同的元素,我不能使用链接。
Just to make myself clear, these two items which I am sliding one and fading the other are different elements and I can not use chaining.
有没有办法让这些函数同时或更接近地运行,以便它们看起来像是同时运行?
Is there any way to get these functions to run at the same time or closer together so that they appear they are running at the same time ?
这是我正在使用的jQuery代码:
Here is the jQuery code that I am using:
$(document).ready(function(){
$('#trigger').click( function(){
$(this).animate({ opacity: 0.0 }); // fade
$('#carousel').animate({ top: '100px' }); // slide
$('#pullrefresh').css('top', '-490px'); // line 5
$('#detector').hide(); // line 6
});
});
淡入淡出和幻灯片发生在不同的时间,第5行和幻灯片似乎发生在同时。
The fade and the slide are happening at different times, line 5 and the slide seem to be occurring at the same time.
推荐答案
如果你这样做,它们应该一起运行:
They should run together if you do it like:
$('#element1').animate({
opacity: 0.25,
}, 1000, function() {
// complete
});
$('#element2').animate({
opacity: 0,
}, 1000, function() {
// complete
});
这篇关于同时运行两个jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!