Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery callback on custom function
    primarykey
    data
    text
    <p>The callback on my custom function is not working. Please would anyone help me ?</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script src='jquery-1.8.2.js'&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(e){ function cb(){ alert('animation finish'); } $('button').bind({ 'click':function(e,cb){ e.preventDefault(); $('div').animate({'height':200,'width':200},1000); cb(); } }) }) &lt;/script&gt; &lt;style&gt; div{ height:5px;width:5px;background-color:yellow; } &lt;/style&gt; &lt;button&gt;click me&lt;/button&gt; &lt;div&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>edited:</strong> I cannot do the <code>.animate(...,1000,function(){...})</code> I used the line</p> <pre><code>$('div').animate({'height':200,'width':200},1000); </code></pre> <p>just to represent some other functions in execution -- it is relative complicated, with more conditions, and different animations called depending upon various parameters.</p> <p>Basically, after all those animations are over, I want a end function <code>cb()</code> to execute; which is where I am having the problem.</p> <p>Maybe something like this would be appropriate : </p> <pre><code>&lt;script&gt; $(document).ready(function(e){ var status=0; var tmp1=2;tmp2=7; function cb(){ alert('animation finish'); console.log(status); } function do_func1(){ status = tmp1+tmp2; $('#ele1').animate({'height':200,'width':200},1000); } function do_func2(){ status = tmp1*tmp2; $('#ele2').animate({'height':300,'width':300},2000); } function do_func3(){ status = tmp1+tmp1; $('#ele3').animate({'height':400,'width':400},500); } function func1(){ if('a'=='b'){ do_func1(); }else if('a'=='c'){ do_func2(); }else{ do_func3(); } } $('button').on({ 'click':function(e,cb){ e.preventDefault(); func1(); cb(); } }) }) &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload