JQuery: How to use jQuery delay using my own function?

How to use jQuery delayin conjunction with my own specific function, pseudocode like so ?:

$('#foo').slideUp(300).delay(800).myOwnFunction(1,2,3);
function myOwnFunction (a,b,c) {...}

The code above does not work, however - in the jQuery documentation it seems like it should.

+3
source share
2 answers

Use setTimeout()here. After the animation finishes moving up, it will launch an anonymous function that wraps setTimeout(), which calls your function after about 800 milliseconds.

$('#foo').slideUp(300, function() {

    setTimeout(function() {

       myOwnFunction(1, 2, 3);

    }, 800);

});




function myOwnFunction(a, b, c) {
       alert(a + b + c);
   };

It does not matter that it was defined below, since its definition should be raised to the top.

+4
source
$('#foo')
    .slideUp(300)
    .delay(800)
    .queue(function () {
        myOwnFunction(1,2,3);
        $(this).dequeue();
    });

Cm:

+1

Source: https://habr.com/ru/post/1742407/


All Articles