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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:01:12+00:00 2026-05-28T04:01:12+00:00

In the following code snippet: var scr_h = $(document).height(); var scr_w = $(document).width(); var

  • 0

In the following code snippet:

var scr_h = $(document).height();
var scr_w = $(document).width();
var logo = {                                                             
    width   :   (scr_w*.25),                                              
    img     :   document.createElement('img'),                           
    src     :   'images/static/mk_vc.png'                                
};  
$(logo.img).attr('src', logo.src);                                       
$('#logo').append(logo.img);                                             
$('#logo').css({                                                         
    'margin-top'    :   scr_h*.15+'px',                                       
    'width'         :   logo.width+'px',
    'left'          :   (scr_w/2)-(logo.width/2)+'px' //this doesn't always work...
}); 
alert($('#logo').css('left'));        

Sometimes the alert comes back with “auto” instead of the correct number. It usually happens if the page is refreshed (though a ctrl+refresh will usually fix the issue). I tried rendering the page via php and attaching a ?randomnumber=$randomnumber parameter to the JavaScript call, but it didn’t help, which means it’s not a caching issue of some sort.

It also seems to happen in all browsers. My client has a Mac, and has tried with Chrome and Safari, and I have Linux and have tried it in Chrome and Firefox.

Any thoughts at all? The rest of the JavaScript functions fine, regardless as to whether that particular line renders properly. The margin-top and width css also always functions. It appears to be only the left that gives issues.

I tried changing the order to render “left” first, but that also did not help, though the other two attributes were still just fine.

The full script can be seen at http://meenakhalili.turnleftllc.com/scripts/js/dev/mk.js, with the site at meenakhalili.turnleftllc.com. Try refreshing a few times. You’ll see the problem.

  • 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-28T04:01:12+00:00Added an answer on May 28, 2026 at 4:01 am

    Chchrist answered this question last night in the comments. Setting the calculation to occur after the onload event of the image fixed the problem.

    I’m posting this for now, but would love to give credit where it’s due!

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

Sidebar

Related Questions

Take the following code snippet: <script> var x = 25; document.write(x << 9); </script>
I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,
Say I have the following code snippet in c# static const bool DO_PERFORMANCE_CODE =
I have the following code (snippet): var numRows = $table.find('tbody tr').length; var numPages =
I have the following code snippet: var matchingAuthors = from authors in DB.AuthorTable where
I have following code snippet in c#. var list = new List<string> { a,
Looking at the following code snippet : public JsonResult GetMapList(string siteDescription,string siteStatus) { var
I'm attempting to create a new user using the following code snippet. using (var
I have following code snippet: var reg = /^[0-9]$/; $('input[type=text]').keypress(function(){ console.log(reg.test(parseInt($(this).val()))); }); When I
I have the following code snippet in C#: var actions = new List<Func<int>>(); IEnumerable<int>

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.