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 6959201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:14:25+00:00 2026-05-27T15:14:25+00:00

I have an application that generates div boxes dynamically. The boxes are overlapping each

  • 0

I have an application that generates div boxes dynamically. The boxes are overlapping each other, and moved 15px down and to the right.

However, when the bottom of a box hits the bottom of the page I want the next box to turn up on the top on the page. The same goes for when the right side of a box hits the right side of the page (ie. the boxes shouldn’t be able to go outside the page).

Below is my code, but it doesn’t work as I want. The boxes gets “out of bounds” on the right side before turning up on the left side, and regarding the bottom it’s not really right either. I guess there is a better way to accomplish this, I just don’t know what it is.

var win = $('<div/>', {
    'class': 'window',
    'width': this.width,
    'height': this.height
}).appendTo('#container');

var containerHeight = $('#container').height();
var maxBottom = (desktopHeight / 2);

var containerWidth = $('#container').width();
var maxRight = desktopWidth;

var prev = win.prev('.window');
if (prev.length > 0) {

   win.offset({ 
    left: prev.offset().left + 15, 
    top: prev.offset().top + 15 });

    if (prev.offset().top >= maxBottom){
        win.offset({
            top: 10
        });
    }
    if (prev.offset().left >= maxRight){
        win.offset({
            left: 0
        })
    }
}
  • 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-05-27T15:14:26+00:00Added an answer on May 27, 2026 at 3:14 pm

    You can check if the element’s .offset().top property plus the element’s .height() are equal or greater than the .height() if the document:

    var myBox   = $('#my-box'),
        bHeight = myBox.height(),
        wHeight = $(window).height(),
        bWidth  = myBox.width(),
        wWidth  = $(window).width();
    
    if (myBox.offset().top + bHeight >= wHeight) {
        myBox.css({
            top : 0
        });
    }
    
    if (myBox.offset().left + bWidth >= wWidth) {
        myBox.css({
            left : 0
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that generates around 10000 printed pages per month. Each report
I'm using C# and i have written a locally installed application that dynamically generates
I have a some of html strings that my application generates. Each html 'snippet'
I have an application that generates tables for reports; however during printing - the
Right now I have an application that generates an XML file. We'll call it
I have DIV ids in an application that are generated dynamically, with an ID
We have an application that generates simulated data for one of our services for
I have a application that generates a couple of different mails. These mails are
Background: we have an application that generates reports from HTML (that may or may
I have a Winforms application that generates its own PrintDocument object for printing. It

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.