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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:10:46+00:00 2026-05-22T16:10:46+00:00

I’m using a jQuery plugin that invokes a callback once all images on page

  • 0

I’m using a jQuery plugin that invokes a callback once all images on page have been loaded. It checks the imageObject.complete property and binds a handler to the load and error events to determine when image loading is done.

This works well, but the problem I’m running into is that, even though an image is considered loaded, when I inspect the height and width properties of the image or its containing div element, the dimensions have not yet been updated.

Here’s an example:

http://jsfiddle.net/RtnVx/12/

How can I ensure that the containing element has been resized to fit the image before attempting to access its height and width dimensions?

EDIT 1: I cleaned up and commented the code in my jsfiddle to make the example easier to understand.

EDIT 2: There must be a race condition or variation based on caching because when I run the code from a different machine, it works properly (i.e., the top margin is calculated properly), which is actually not good because it is not consistent. The inconsistencies are more apparent in Chrome, FWIW.

Also, to be clear, the goal isn’t to call init every time an image loads; rather, init should be called once after all images have been loaded via the AJAX load invocation.

  • 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-22T16:10:47+00:00Added an answer on May 22, 2026 at 4:10 pm

    Answer: http://jsfiddle.net/morrison/RtnVx/30/

    You needed to not call batchImageLoad until the image was done loading. I created an event on the loaded image.

    Updated Notes:

    • I cut out your jQuery plug-in. It was overly complex and I didn’t completely understand it.
    • My current solution provides error handling by using the error event, as did the plug-in.
    • The solution process:
      • Find all the img‘s descending from #slides and store that length in a .data() attribute, as well as a variable to keep how many have loaded.
      • Bind a load and error events on each img which updates the count of loaded images.
      • If the count of loaded/errored images hits the total image count, call setTimeout() until all of them have widths greater than zero then fire init().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am reading a book about Javascript and jQuery and using one of the
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.