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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:14:24+00:00 2026-06-08T07:14:24+00:00

I have a very sad tomato, because it’s not resizing, poor thing. If I

  • 0

I have a very sad tomato, because it’s not resizing, poor thing. If I don’t put the “load” function then some of my thumbs won’t resize, and if I do then the other ones won’t resize.

startDiv.find('img').each(function(p) {
    $(this).parent().css({ height: thumbs_size, width:thumbs_size });
    $(this).css({ height: thumbs_size, width: thumbs_size }); //temporary
    $(this).load(function() {
        if ($(this).height() > $(this).width()) {
            var w = thumbs_size;
            var h = Math.ceil($(this).height() / $(this).width() * thumbs_size);
        } else {
            var h = thumbs_size;
            var w = Math.ceil($(this).width() / $(this).height() * thumbs_size);
        }
        $(this).css({ height: h, width: w });
    });
});

Can anyone save my tomato?
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-08T07:14:27+00:00Added an answer on June 8, 2026 at 7:14 am

    It’s because some may already be loaded when you call $(this).load( . Do the following, or something like it

    startDiv.find('img').each(function(p) {
        $(this).parent().css({ height: thumbs_size, width:thumbs_size });
        $(this).css({ height: thumbs_size, width: thumbs_size }); //temporary
    
        var $this = $(this);
        function onLoad() {
            var height = $this.height(), width = $this.width();
            var isPortrait = height > width;
            var w = isPortrait ? thumbs_size : Math.ceil(width / height * thumbs_size);
            var h = isPortrait ? Math.ceil( height / width * thumbs_size) : thumbs_size;
            $this.css({ height: h, width: w });
        }
        // Set it on the load event handler in case it's not loaded
        // If it has a width, it's already loaded
        if ($(this).width() > 0) {
            onLoad();
        } else {
           $this.load(onLoad);
        }
    });
    

    Or you could just use it in the onload handler which guarantees that all images in the DOM are loaded (also all scripts)

    $(window).load(function(){
        startDiv.find('img').each(function(p) {
            $(this).parent().css({ height: thumbs_size, width:thumbs_size });
            var height = $this.height(), width = $this.width();
            var isPortrait = height > width;
            $this.css({ 
                height: isPortrait ? Math.ceil( height / width * thumbs_size) : thumbs_size,
                width: isPortrait ? thumbs_size : Math.ceil(width / height * thumbs_size) 
            });
        });    
    });
    

    You may want to give your images default widths and heights with CSS

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

Sidebar

Related Questions

I have a very simple perl script that moves files (don't ask why i
I have very simple query. I want to make sure that I don't have
I have very big problem in my SQL query and i don't know how
I have very odd problem and I don't know how to get rid of
i have very serious problem if any tech expert can help...thank you in advance..
I have very simple piece of code. The goal is when i input four-digit
I have very very big html page/data. I need to fetch data under h1
I have very strange problem while I am submitting a practice problem on codechef.
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very simple window where I have 2 buttons - one for cancel,

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.