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

  • SEARCH
  • Home
  • 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 8379495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:12:13+00:00 2026-06-09T16:12:13+00:00

I have been working on this for hours, and I just can’t figure it

  • 0

I have been working on this for hours, and I just can’t figure it out,

Let’s say I have a lot of divs with floating around, with jquery draggable attached to them so, their position keeps changing all the time.

Now I want to be able to space them out vertically, so the space between each div would be the same, one of the biggest issue is that each div’s height also keeps changing.

Each time I try to do it right i just write ~100 lines of code I just get lost in confusion, maybe there is some easy way to do it, by the way, here is example of how it looks like, I didn’t include any of my written code since it doesn’t make much sense.

http://jsfiddle.net/M6PmM/

  • 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-09T16:12:15+00:00Added an answer on June 9, 2026 at 4:12 pm

    It’s interesting to see the different interpretations of your question. When I think of aligning vertically, I think of Adobe Illustrator, and how you can evenly space a number of selected shapes. To that end, you could so something like this:

    NOTE: this could easily be adapted to maintain an even gap between the elements, regardless of their individual heights.

    $('.align').click(function() {
    
        // Cache the elements
        var $obj = $('.obj');
    
        // Sort them by offset top
        $obj = $obj.sort(function(a, b) {
            return $(a).offset().top - $(b).offset().top;
        });
    
        // Get get the offset of the first and last elements
        // NOTE that we included the last element's height... you may need to tweak it
        // here due to CSS borders adding to the height
        var firstOffsetTop = $obj.first().offset().top;
        var lastOffsetTop = $obj.last().offset().top + $obj.last().height();
    
        // The new container height is the difference between the first,
        // and last element's position
        var containerHeight = lastOffsetTop - firstOffsetTop;
    
        // Determine the gap between each element, based on the height of the container
        // divided by the number of elements
        var spacing = containerHeight / $obj.length;
    
        // Assign top properties
        $obj.each(function(i, el) {
            $(this).css('top', (i * spacing) + firstOffsetTop + 'px');
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright I've been working on this for hours now and can't figure out my
I have been working on this for few hours and got stuck, so how
I have been working on this for 24 hours now, trying to optimize it.
Have been working on this question for a couple hours and have come close
i have been working on this sub-menu for 8 hours now, the last little
I've been working on this problem for a few hours and have used many
I have been working on this app for at least 3-4 months and just
I've been at this for hours but it just isn't working. I'm trying to
I've been struggling with this for a few hours. Everything just stopped working and
I have been at this for hours and MUST get this working! It 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.