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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:10:51+00:00 2026-06-12T12:10:51+00:00

I have made a script: http://jsfiddle.net/radar24/XZgh4/ which scales the given dimension into the outer

  • 0

I have made a script: http://jsfiddle.net/radar24/XZgh4/ which scales the given dimension into the outer div. everything seems fine, until I enter a dimension such as 200 x 99. then the box grows outside.

I really cannot find the cause of this, can anyone help?

  • 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-12T12:10:52+00:00Added an answer on June 12, 2026 at 12:10 pm

    The problem is that you’re not restricting your proportions along both axes. Your box has a height:width proportion of 5:3. If you don’t restrict along both axes, you can have bleeding outside of the boxes. An example might show this best.

    Take the case of the height being the bigger of the two dimensions. Your code is only restricting it along the 500px axis. Consequently, if we throw a box in there with 5: >3 proportions, you get a creeping edge.

    For instance, put “3” and “5” in your boxes. Fits perfectly. Now make it 3.1 and 5. Ruh roh.

    You’ll need to add another if statement in each section that THEN determines if the dimension ratio goes outside this boundary. In the above case, you’ll need to make it so that the height of the 5:3.1 is not 500px, but rather, the height (less than 500px) that would make 3.1 to be equal to 300px. That would be 483px.

    Does that makes sense?

    If not, I’ll try to rephrase again:

    Put another set of if statements in the two if statements you already have. These check if, upon setting the LARGER dimension, it makes the SMALLER dimension go outside the bounds of the box in that direction.
    in pseudocode

    if (height > width)
        calculate the height
        calculate the width
        if (width > div.width)
           width = div.width
           height = div.width * aspect;
    

    Just ask me if this isn’t clear enough!

    Edit: Here’s a JSFiddle that gets it right. You’ll need to add further code if you want a white border along each edge.

    Edit2: Here’s the white border come back!

    Edit3: You can also try prettying it up and using just aspects to do this. I did the first one for you. Three to go!

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

Sidebar

Related Questions

I have made small jquery collapse/expand script http://jsfiddle.net/goldie/QFL49/ (please don't pay attenton to html/css
I have this script: http://jsfiddle.net/NV2uV/ It works, but I do not like it. Cons:
EDIT: I just made a jsfiddle to demonstrate the problem here: http://jsfiddle.net/GvjRd/3/ I have
http://jsfiddle.net/Cyjye/ I m new to jquery. I have made html table shown in jsfiddle.Firstly
I have a problem. I have made a script to convert a given HTML
hi i'm using a script made by http://snook.ca/archives/javascript/simplest-jquery-slideshow so basically the code i have
For a site i made, http://crystalmurray.com , i have a simple little script to
I have made a script to login into Vbulletin through API here is the
I've made a demo of what I'm trying to do here in jsFiddle: http://jsfiddle.net/clowerweb/SbNdb/
I have made a script, but it's not working as expected, and I need

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.