Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should swap the elements in the DOM also, because when you animate the HTML elements, they just change theirs place on the screen.</p> <p>I have completed your script:</p> <pre><code>$('.editUp', this).click(function() { var this_rowCont = $(this).parents('.rowCont'); var prev_rowCont = $(this).parents('.rowCont').prev(); // if this is the first element, it returns if (prev_rowCont.length != 1){return false;} thisRowHt = this_rowCont.outerHeight(); upperRowHt = prev_rowCont.outerHeight(); this_rowCont.animate({'top': '-=' + thisRowHt + 'px'}); prev_rowCont.animate({'top': '+=' + upperRowHt + 'px'}, function(){ // this is a callback function which is called, when the animation ends // This swap this and previous element in the DOM this_rowCont.insertBefore(prev_rowCont); this_rowCont.css("top", 0); prev_rowCont.css("top", 0); }); return false; }); $('.editDown', this).click(function() { var this_rowCont = $(this).parents('.rowCont'); var next_rowCont = $(this).parents('.rowCont').next(); // if this is the last element, it returns if (next_rowCont.length != 1){return false;} thisRowHt = this_rowCont.outerHeight(); lowerRowHt = next_rowCont.outerHeight(); this_rowCont.animate({'top': '+=' + lowerRowHt + 'px'}); next_rowCont.animate({'top': '-=' + thisRowHt + 'px'}, function(){ // This swap this and next element in the DOM next_rowCont.insertBefore(this_rowCont); this_rowCont.css("top", 0); next_rowCont.css("top", 0); }); return false; });​ </code></pre> <p>You can see it in action here: <a href="http://jsfiddle.net/ykzwT/2/" rel="nofollow">Animate div up and down</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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