У меня есть функция, которая работает так, как я ее тоже хочу, только она выглядит действительно беспорядочной и раздутой, и поэтому мне интересно, есть ли лучший способ кодировать ниже?Оптимизация обратных вызовов jQuery
function careerFlyIn(){
var distance = $('.row').offset().top,
$window = $(window);
var distance = distance - 200;
var flyInR = $('.path-description');
var flyInL = $('.path-title');
$window.scroll(function() {
if ($window.scrollTop() >= distance) {
$('.career-path .row:first-child').find(flyInL).animate({ 'left' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(2)').find(flyInL).animate({ 'left' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(3)').find(flyInL).animate({ 'left' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(4)').find(flyInL).animate({ 'left' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(5)').find(flyInL).animate({ 'left' : '0px' } ,400, 'easeOutBounce', function() { });
});
});
});
})
$('.career-path .row:first-child').find(flyInR).animate({ 'right' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(2)').find(flyInR).animate({ 'right' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(3)').find(flyInR).animate({ 'right' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(4)').find(flyInR).animate({ 'right' : '0px' } ,400, 'easeOutBounce', function() {
$('.career-path .row:nth-child(5)').find(flyInR).animate({ 'right' : '0px' } ,400, 'easeOutBounce', function() { });
});
});
});
})
}
});
};
Почему downvote? Это работает и является полезной техникой для многих асинхронных проблем. –