1

I'm scratching my head as to why I'm getting two callbacks when running this function.

lE = $(this).clone().appendTo('body');

// Hide submenu
$('nav>ul>li>ul').fadeOut(100, function() {
    // Animate clone
    $(lE).animate({ 'top': '160px' }, 100, function() {

        console.log('aaa'); // PRINTS TWICE IN CONSOLE

        $(lE).animate({ 'left': '150px' }, 300, function() {
            $(lE).addClass('lE');
        });
    });
});

As you can see I start by assigning a clone to lE. Surely lE can only be a single element at this point no?

I then proceed to run a three animations within each other but the second animation get's called back twice. I can't understand why.

Pramod
  • 2,828
  • 6
  • 31
  • 40
Juicy
  • 11,840
  • 35
  • 123
  • 212

1 Answers1

-1

I've got problems while using multiple chain callbacks before. Try to use setTimeout instead of function callbacks. This method worked on me before.

lE = $(this).clone().appendTo('body');

$('nav>ul>li>ul').fadeOut(100);

setTimeout(function() {
    $(lE).animate({ 'top': '160px' }, 100);
},100);

setTimeout(function() {
    $(lE).animate({ 'left': '150px' }, 300, function() {
        $(lE).addClass('lE');
    });
},200);
Barlas Apaydin
  • 7,233
  • 11
  • 55
  • 86