How to use .queue () to properly configure custom callback functions?

I am trying to figure out how to configure custom functions:

I have something like this:

show_loader(0, function() {
    open_box($target_open, event.value, '.wide-col', function() {
        hide_loader(function() {
            scroll_to_content($target_open, function() {
            });
            $(this).dequeue();
        });
        $(this).dequeue();
    });
    $(this).dequeue();
});

These functions perform a callback that looks something like this:

function show_loader(position, callback) {
    $ajaxSpinner.fadeIn();
    status = "loading"; //some non-jQuery stuff
    if (callback) $ajaxSpinner.queue( function() {callback()} );
}

You can see the basic idea of ​​what I'm trying to do: execute my functions after the animations inside the functions have completed.

I do not think my code is absolutely right. The order should be: show the bootloader, open a window, hide the bootloader, and then finally scroll through the contents. Instead, it seems that this is what actually happens when I test it: show the bootloader, hide the bootloader, scroll to the contents, then open the window.

, ? keyowrd "this" ?

+3
1

, : .

jQuery, . :.

function show_loader(position, callback) {
    $ajaxSpinner.fadeIn(callback);
    status = "loading"; //some non-jQuery stuff
}

http://api.jquery.com , .

Update:

, queue. , . , - dequeue. : , . , queue .

+1

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


All Articles