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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:00:25+00:00 2026-05-19T09:00:25+00:00

I am displaying a profile image. If that image is bigger than certain dimension

  • 0

I am displaying a profile image. If that image is bigger than certain dimension I want to scale it so I attach an onload event to that image. After the image has loaded I will check whether it is greater and if so then I will scale it to a smaller image. I am displaying a loading animation till the image loads.

<td height="203" valign="middle" align="center"><div id="loadingdiv">Loading...
</div><img style="display:none;" id="proimg" src="<?=$path?>" />
</td>

<script type="text/javascript">

var pro = document.getElementById('proimg');
pro.onload = function()
{
    if(this.width>260)this.style.width = '260px';
    if(this.height>200)this.style.height = '200px';
    window.setTimeout(function() {
        document.getElementById('loadingdiv').style.display = 'none';
        this.style.display = 'inline';

    },1000);
}

</script>

The loading animation will fade and the image will be visible after a second. That is what I want so I did it like the above, but how to refer the this of onload into settimeout event handler?

Without the settimeout it works fine and I can go with that but I just want to show a delay.

EDIT:

I use to do like the first reply, but I thought that there should be another way or concept of doing this.

IS THERE ANYTHING I CAN DO WITH CLOSURES HERE? SO THAT I DON’T HAVE TO USE EXTRA VARIABLE REFERENCES.

  • 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-19T09:00:25+00:00Added an answer on May 19, 2026 at 9:00 am

    You cannot use the this keyboard inside an anonymous event handle function, but you can still make a reference of the current this and then use that reference to call the methods/properties on the object. Here’s an example :

    var that = this;
    window.setTimeout(function() {
        that.style.display = 'inline';
    }, 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am displaying a texture that I want to manipulate without out affecting the
I'm displaying a 68x68 pixel image into my iPhone app. That's the resolution of
I have an User object that has many attributes. In my edit profile screen
When displaying my DateTime values, I want them to be formatted like so: February
I am displaying a scrolled data table in a web page. This table has
I'm displaying a series of images in a UIScrollView. I pretty much want to
I have some text displaying in a larger font size than what it is
So it just occurred to me that once I upload profile pics to S3,
We have a very simple page for displaying the records. Basically, it passes certain
I have a webpage that requires login. Once a user has logged in I

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.