Friday, 16 August 2013

Optimising jQuery callbacks

Optimising jQuery callbacks

I have a function that works as I want it too, only it looks really messy
and bloated and so im wondering, is there a better way to code the below?
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 () { });
});
});
});
})
}
});
};

No comments:

Post a Comment