Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8796171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:33:38+00:00 2026-06-13T23:33:38+00:00

I have the following code to animate a dynamic div up and down. The

  • 0

I have the following code to animate a dynamic div up and down. The idea is that there could be any number of divs that need to be moved up and down the stack, swapping positions with the divs above and below. Once in their new position, I need to be able to catch that new re-odered position. The following code works, once, but once a lower div moves up and a upper moves down (swap spots) to the new positions, they stop working. How can I set this up so that they will continue to traverse up the stack, swapping the one immediately above or below as they go? I also need to know the new positions once finished to update the database. Ive been looking everywhere but can’t seem to find how to do this. Any help would be much appreciated.

$('.editUp', this).click(function() {
   thisRowHt = $(this).parents('.rowCont').outerHeight();
   upperRowHt = $(this).parents('.rowCont').prev().outerHeight();
   $(this).parents('.rowCont').animate({'top': '-=' + thisRowHt + 'px'});
   $(this).parents('.rowCont').prev().animate({'top': '+=' + upperRowHt + 'px'});
   return false;
});

$('.editDown', this).click(function() {
   thisRowHt = $(this).parents('.rowCont').outerHeight();
   lowerRowHt = $(this).parents('.rowCont').next().outerHeight();
   $(this).parents('.rowCont').animate({'top': '+=' + lowerRowHt + 'px'});
   $(this).parents('.rowCont').next().animate({'top': '-=' + thisRowHt + 'px'});
   return false;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:33:40+00:00Added an answer on June 13, 2026 at 11:33 pm

    You should swap the elements in the DOM also, because when you animate the HTML elements, they just change theirs place on the screen.

    I have completed your script:

    $('.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;
    });​
    

    You can see it in action here: Animate div up and down

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that seems to scroll a div on click all
I have the following code that works inside a function: $('#MyPanel').stop().animate({ top: PanelTop },
I have the following code so far: $('div.welcome-handle').click(function() { top.$('#welcome-message').toggle(function() { $(this).animate({left: -=749px}, 500);
I have the following jQuery code: $content.each(function(i) { $body = $(this); $(this).find('div.field-content') .animate( {
I have the following code to animate the showing/hiding of a div. $(.headerClosed, .headerOpen).live(click,
I have the following code which moves a DIV block 20px down on mouseover:
I have the following Javascript code (using jQuery): floatUpAndDown(); function floatUpAndDown() { $(#bird).animate({top: '+=30px'},
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code that I am compiling in a .NET 4.0 project namespace
I have the following code to animate a badge if a certain condition is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.