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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:42:44+00:00 2026-06-04T06:42:44+00:00

Example: http://jsfiddle.net/forgetcolor/rZSCg/3/ Given a div set to overflow:auto, that will (likely) contain an image

  • 0

Example: http://jsfiddle.net/forgetcolor/rZSCg/3/

Given a div set to overflow:auto, that will (likely) contain an image larger than its window, I’m trying to figure out a way to wait for that image to load before querying its properties. The property I’m after is it’s inner width, minus its scrollbar. Thanks to a previous stackoverflow question (http://stackoverflow.com/questions/10692598/how-to-get-innerwidth-of-an-element-in-jquery-without-scrollbar) I’ve got a technique to do it, but this only works with a small tiny image, or one in the cache. When it gets a large image, the code that does the query executes before the image is done loading.

What I want is a way to wait for that image to load before doing the query. Any ideas?

Full example: http://jsfiddle.net/forgetcolor/rZSCg/3/

Javascript:

// using a random appended to the URL to simulate non-cached
// varying images
var r = Math.floor((Math.random()*100000)+1);
$('#box1').html("<img src='http://lorempixel.com/output/fashion-q-c-1920-1920-4.jpg?"+r+"' />");
var helperDiv = $('<div />');
$('#box1').append(helperDiv);
$('#iw').text("inner width is: " + helperDiv.width());
helperDiv.remove();
  • 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-04T06:43:06+00:00Added an answer on June 4, 2026 at 6:43 am
       var r = Math.floor((Math.random()*100000)+1);
       var newImage = new Image()
       $(newImage).load(function(){
            $('#iw').text("inner width is: " + newImage.width);
       });
       newImage.src = 'http://lorempixel.com/output/fashion-q-c-1920-1920-4.jpg?'+r
    

    The problem you are encountering is abit more complex. Images from the DOM have odd loading behaviors, where onload events do not always fire. So placing the image into a div then waiting for the DOM element to fire onload, is not going to work.

    As a result we need the built in javascript image object. (recently learned) that this object will solve both your problems. First as long as you set your .load listener before you set the image source, it will fire onload every time in every browser. After the load has occurred, because its an image object, you don’t need to add it to the page to get it’s height and width, those properties are built in.

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

Sidebar

Related Questions

example: http://jsfiddle.net/kuTLf/ code looks like this: <div id=main> <div id=slideshow class=pics> <div id=nav></div> <img
See example http://jsfiddle.net/qqyYU/1/ <div class=detail> <p><b>Entry</b><br> First <span>40,-</span><br> Second <span>20,-</span></p></div> css .detail p span:first-child
I have seen this example: http://jsfiddle.net/UwEe2/306/ that is implemented with scrollleft . Now I
Example: http://jsfiddle.net/NBWmU/1/ I'm using the following CSS to make the background of my div
I prepared a jsfiddle example: http://jsfiddle.net/PEH7t/11/ The problem is that I have a container
in my example http://jsfiddle.net/radek/HnXC4/2/ I defined jQuery handler for click on button that have
If you look at this jsFiddle example: http://jsfiddle.net/jrXwf/1/ You will see the UL tag
Consider this example: http://jsfiddle.net/treeface/P8JbW/ HTML : <div id=test> <img src=http://ycombinator.com/images/y18.gif /> </div> CSS :
Please take a look at the following example: http://jsfiddle.net/MVfVD/ I want the overlayedFrameFooter div
I think it is best described by looking at an example: http://jsfiddle.net/kV9yn/16/ That 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.