How to chain events in jQuery?

I have something to do one by one, and not all methods have callback functions, and what is the best way to link these events together?

I have something like this

Close Slider> Delete Old Content> Add New Content> Override Slider

I'm new to jQuery, so this may seem obvious, but I appreciate any help!

+3
source share
2 answers

You can use queues and an explicitly defined queue, but in this case, you can simply use the callback with . slideUp () .

, , . slideDown() .slideUp().

$(sliderSelector).slideUp(function() { 
    // delete and add stuff
}).slideDown();

jsFiddle


- - , , , , " ", . queue():

$(this).queue(function() {
      // Stuff to do
    // ...
      // Dequeue
    $(this).dequeue; 
});

, :

    $(this).queue(function() {
        $(this).customUp();
        $(this).dequeue();
    }).queue(function() {
        // Delete & add stuff
        // ...
        $(this).dequeue();
    }).queue(function() {
        $(this).customDown();
        $(this).dequeue();
    });

jsFiddle

+4

jQuery .queue. , ...

$("#theSlider")
  .hide('fast')
  .queue(function(){
    $(this).html( '' ).dequeue();
  })
  .queue(function(){
    $(this).append( some_new_content ).dequeue();
  })
  .show('fast');

, dequeue .

+2

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


All Articles