javascript - How to make functions queue -


i want second function (blockdone) run after animation has finished running in first function.

i know can putting blockdone in callback on animate method. reasons specific project i'm working on, can't this.

is there way queue functions in someway in javascript or jquery?

https://jsfiddle.net/bazzle/mdawnrtq/

function blockmove(){     $('.block').animate({top: '100px'},{duration: 1000} ).animate({width: '0'}); }; function blockdone(){     $('p').text('done'); }; blockmove(); blockdone(); 

under assumption know selection on animations run, can via jquery queue function. literally allows specify function should called when other functions in queue have completed.

you can specify name of queue, more 1 queue can created selection, default queue function works on queue in effects (.animate()) stored. precisely want, hooray!

function blockmove() {    $('.block').animate({      top: '100px'    }, {      duration: 1000    }).animate({      width: '0'    });  };    function blockdone() {    $('p').text('done');  };    blockmove();  $('.block').queue(blockdone); // <-- changed
html,  body {    margin: 0;  }    .block {    background-color: red;    width: 100px;    height: 100px;    display: block;    position: relative;  }    p {    position: absolute;    top: 1em;    right: 1em;    text-align: right;    display: block;    margin: 0;  }
<div class="block"></div>  <p></p>    <script src="https://code.jquery.com/jquery-2.2.4.min.js"          integrity="sha256-bbhdlvqf/xty9gja0dq3hiwqf8lacrtxxzkrutelt44="          crossorigin="anonymous"></script>


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -