Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>.bind</code> requires you pass it a function as the 2nd parameter.</p> <pre><code>function clickFunc(){ // Give the event function a name $('#in-right').unbind('click'); imageSwitch(); $('#in-right').click(clickFunc); // .click is shorthand for `.bind('click',` } $('#in-right').click(clickFunc); </code></pre> <p><strong>EDIT</strong>: You should make your <code>imageSwich</code> function take a callback, so it can re-bind the function once it's done animating.</p> <pre><code>function imageSwitch(callback){ // code... } function clickFunc(){ // Give the event function a name $('#in-right').unbind('click'); imageSwitch(function(){ $('#in-right').click(clickFunc); }); } $('#in-right').click(clickFunc); </code></pre> <p>As for making sure the callback runs once all the animations are done, we can use jQuery's <a href="http://api.jquery.com/category/deferred-object/" rel="nofollow">deferreds</a>.</p> <p>Basically, you want to save the objects returned from <code>.animate</code> into varibles. Then use <code>$.when</code>, and <code>.then</code> to run the callback at the correct time.</p> <p>(This is untested, BTW)</p> <pre><code>function imageSwitch(callback) { var animations = []; current++; current_image++; previous_image++; next++; two_prev++ if (two_prev &gt;= divs.length) { two_prev = 0; } if (current &gt;= gallery_images.length) { current = 0; } if (previous_image &gt;= divs.length) { previous_image = 0; } if (current_image &gt;= divs.length) { current_image = 0; } if (next &gt;= divs.length) { next = 0; } animations.push($('#' + divs[current_image] + '').animate({ left: '-=1020px' }, { queue: false, duration: 1000 })); $('#' + divs[current_image] + '').css('background-image', 'url(' + gallery_images[current] + ')'); animations.push($('#' + divs[previous_image] + '').animate({ left: '-=1020px' }, { queue: false, duration: 1000 })); animations.push($('#' + divs[next] + '').animate({ left: '+=1020px', top: '-=10000px' }, 1000)); animations.push($('#' + divs[two_prev] + '').animate({ left: '+=1020px', top: '+=10000px' }, 1000)); if (typeof callback === 'function') { // Apply is used here because `$.when` expects to passed multiple parameters $.when.apply($,animations).then(callback); } } </code></pre> <p>Deferred and animations demo: <a href="http://jsfiddle.net/M58KK/" rel="nofollow">http://jsfiddle.net/M58KK/</a></p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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