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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:27+00:00 2026-05-16T10:11:27+00:00

Having a bit of an issue please see the following code: window.onload = function

  • 0

Having a bit of an issue please see the following code:

window.onload = function () {

    var imgHeight = $("#profile_img").height();

    var infoPanels = imgHeight - 6;
    //include borders and margin etc..
    var infoPanelsHeight = infoPanels / 4;
    $('.resize').css("height",infoPanelsHeight + "px"); 
    $('.resize2').css("height",infoPanelsHeight + "px");
}

What i’m trying to do is find the height of an image (floated:left), then divide it by 4 and use the outcome to set the height of 4 divs (floated:right), so they equal the height of the image in total.

I’m using this on a resizing project of mine but because the image height depends on the viewing window (in this case a mobile screen), the number is very rarely rounded up correctly so the divs are always out by 1-4 px.

So for a work around I want to find the height of the image, then if the height isn’t dividable by 4 adjust so it is… resize the image then resize the divs using the new image height.

So my question is how do i check the height of the image, if it isn’t dividable by 4 then make it so it is?

I’m using jquery and javascript generally.

Thanks for your help in advance.

Sam Tassell.

  • 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-16T10:11:28+00:00Added an answer on May 16, 2026 at 10:11 am

    I would try:

     if (imgHeight % 4 != 0) { // checks if the imgHeight is not dividable by 4
        $("#profile_img").attr("height") = Math.floor(imgHeight / 4) * 4; // set lowest height that is dividable by 4
     }
    

    Note:

    • The image may become a little blurry because the result depends on your browser capabilities.
    • % is called modulus operator
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue with the following bit of code. I'm trying to
I am having a bit of an issue with my _callback function: What I
I'm having a bit of issue converting the following t-sql statement to Linq (using
I'm having a bit of a odd issue with my height of tables. I
I'm having a bit of an issue uploading files to a database. I'll post
I am having a bit of a issue. I have an NSMutableDictionary with 10
I'm having a bit of an issue. I'm trying to parse an XML file
I am having a bit of an issue with any rotation around the x-axis
I'm having a bit of an issue with a query and scaling that query
I'm new to C# and I'm having a bit of an issue when saving

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.