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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:51:34+00:00 2026-05-12T20:51:34+00:00

I know that the title is very subtle but I have absolutely no idea

  • 0

I know that the title is very subtle but I have absolutely no idea how I should title this issue nor what the hell is happening with this function.

function update_background(source, isSystem){
    if (!isSystem) {
        source.replace(/\/tn_/, '');
        jQuery('div#drag_container img[alt="background"]').attr('src', source); //*1
        jQuery('div#drag_container img[alt="background"]').attr('style', '');
        var height = jQuery('div#drag_container img[alt="background"]').height();
        var width = jQuery('div#drag_container img[alt="background"]').width();
        var ratio = Storyboard['format'];
        //Don't touch the paddings, they are correct!
        if (height * ratio > width) {
            var padding = (Storyboard['display'] - (width * (Storyboard['height'] / height))) / 2;
            jQuery('div#drag_container img[alt="background"]').css({
                'height': Storyboard['height'],
                'padding-left': padding
            });
        } else {
            var padding = (Storyboard['height'] - (height * (Storyboard['display'] / width))) / 2;
            jQuery('div#drag_container img[alt="background"]').css({
                'width': Storyboard['display'],
                'padding-top': padding,
                'padding-bottom': padding
            });
        }
    } else {
        jQuery('div#drag_container img[alt="background"]').attr('src', source).attr('style', '');
        jQuery('div#drag_container img[alt="background"]').css({
            'width': Storyboard['display'],
            'height': Storyboard['height']
        });
    }
}

What this function is supposed to do, is take a picture, get the size of it, compare it to the the size of the container it will be shown in, resize it so that it is as big as possible without sticking out of the container and then finally, apply padding where needed to center the image. It does not matter if the picture is landscape or portrait, the function knows exactly what to do. The picture is cached so that we don’t get wrong values (I already had a bug like that). In case it is a System Background, we don’t care for correct size and padding. Worked flawless for 3 months.

Lately, it is behaving rather odd. At the line with the comment *1, it does not only reset the src attribute of the img-tag, but it also sets a height and a padding, as if it already were in the padding calculations. They are removed again on the next line (which wasn’t actually inserted for that purpose but was inserted to get the original dimensions of a picture) and it still works.

Unless, of course, you let the function run at regular speed, where it does not reset the style. I am quite irritated by this Bug as I have no idea where to start searching.

The function is only called once. It only runs once through the function. It is not included in an event and this function is called in 2 totally different places.

Any ideas?

Edit 1

I have found out that the Bug does not occur in every Browser.

  • Mac OS X Snow Leopard
    • Firefox: behavior as described
    • Opera: does it all wrong, but is not supported by our company
    • Safari: Still works flawless
  • Windows XP
    • Chrome: Works same as Safari
    • Firefox: Behavior as described
    • IE8: Same Behavior
    • IE7: Actually Works!
  • Linux
    • Firefox: Behavior as described
    • Konqueror: does not even work with my JavaScript
  • 1 1 Answer
  • 1 View
  • 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-12T20:51:34+00:00Added an answer on May 12, 2026 at 8:51 pm

    You might be having problems getting the size of the image because it isn’t guaranteed that it has been loaded by the time you’re checking its dimensions.

    var $img = jQuery('div#drag_container img[alt="background"]');
    $img.bind('load', function(){
        // do all of your stuff with the width and the height of the image in here...
        var width = $(this).width();
        var height = $(this).height();
    });
    $img.attr('src', source);  /* kicks off the loading of the image, the bound function 
                                * above will get called when it's done.
                                */
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i didn't really know how to title this question, but here's a thing that
Folks, I know I didn't phrase that title very well, but here's the scenario.
I know the title of this question is not very descriptive, but I didn't
I don't know if the title is right. The thing is that I have
Sorry if the title is not that specific, but I don't know how else
I know, I know. That way madness lies. The title refers to this great
I know that this sort of question has been asked here before, but still
Well, i know the title isn't very specific, but i couldn't find a better
I know this is a very basic concept in Django, and I have tried
I know this is very simple question, but I'm apparently terrible at coding and

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.