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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:00:59+00:00 2026-06-02T07:00:59+00:00

This is my code that fires whenever the window is resized: $(window).resize(function() { setDisplayBoardSize();

  • 0

This is my code that fires whenever the window is resized:

$(window).resize(function()
{   
    setDisplayBoardSize();
});

Fires fine when I resize the window and runs my function just fine, as expected.

If I hit the maximise button though it doesn’t work correctly.

This is the setDisplayBoardSize() function:

function setDisplayBoardSize()
{
    var width = $(".display_container").width();

    for (i=min_columns; i<=max_columns; i++)
    {
        if ((width > (i*(item_width + gap))) && (width < ((i+1) * (item_width + gap))) )
        {
            $("#display_board").css("width",(i*(item_width + gap))+ "px");
        }
    }
}

I think the problem is that when the browser maximise button is clicked it fires the function which reads gets the .display_container width before the resize and then resizes the window to maximum which means that my display_board is incorrectly sized.

If I’m right how can I get the size of the .display_container element after the window has resized to maximum?

Should note I’ve tested this in Chrome and Firefox

Thanks

  • 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-02T07:01:00+00:00Added an answer on June 2, 2026 at 7:01 am

    EDIT for proposed fix:

    Here is the working jsFiddle
    and here is the results only demo.

    As you can see, I totally re-factored your original jQuery code. I removed everything from Global as well as taking out the functions. .resize() expects a function already, so I just do everything inside that one function and then immediately call .resize() to invoke it on the initial page load.

    Another change I made was to increment your for loop backwards, starting with the widest possible width size you allow (5), working my way down to the smallest possible width size you allow (2).

    Also, inside of your for loop, I created j and k variables to make it easier to read those conditions.

    The main change was the if statement. If we are on the max_column iteration and the width of the container is wider k, we want to set the board’s width to k and jump out of the for loop, otherwise we evaluate the original if statement you had, otherwise if we are on the min_column iteration and the width of the container is less than j, we want to set the board’s width to j.

    I tested this in Chrome and it works beautifully. I hope this helps you.

    $(document).ready(function()
    {    
        $(window).resize(function() 
        {
            var item_width = 200, 
                item_height = 300, 
                gap = 20,
                min_columns = 2, 
                max_columns = 5,
                min_width = min_columns * (item_width + gap), 
                max_width = max_columns * (item_width + gap),
                container_width = $(".display_container").width(),
                $display_board = $("#display_board"),
                $display_board_ol_li = $display_board.find("ol > li");
    
            //console.log("container width: " + container_width);
    
            for (var i = max_columns; i >= min_columns; i--)
            {
                var j = i * (item_width + gap),
                    k = (i+1) * (item_width + gap);
    
                //console.log("j: " + j);
                //console.log("k: " + k);
                //console.log("display_board width (before): " + $display_board.css("width"));
    
                if (i === max_columns && container_width > k) 
                {
                    $display_board.css("width", max_width + "px");
                    //console.log("display_board width (after): " + $display_board.css("width"));
                    break;                
                } 
                else if (container_width > j && container_width < k)
                {
                    $display_board.css("width", j + "px");
                    //console.log("display_board width (after): " + $display_board.css("width"));
                    break;
                }
                else if (i === min_columns && container_width < j) 
                {
                    $display_board.css("width", min_width + "px");
                    //console.log("display_board width (after): " + $display_board.css("width"));
                }
            }
    
            $display_board_ol_li.css({
    
                "width" : item_width + "px",
                "height": item_height + "px",
                "margin": gap/2 + "px"
    
            });
    
        }).resize();
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to open multiple files one at a time that is
I have this code that works in a unit test but doesn't work when
Challenge: I have this code that fails to compile. Can you figure out what's
I have this code that I want to make point-free; (\k t -> chr
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
I have the this code that will create excel file and work sheet then
So I have this code that checks 4 parameters (author, title, keyword and subject)

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.