Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery to set width of body based on children width only works after reloading page (used in wordpress)
    primarykey
    data
    text
    <p>I am creating a horizontal layout wordpress theme for a photography portfolio site and used the code example in the post "<a href="https://stackoverflow.com/questions/1015669/calculate-total-width-of-children-with-jquery">Calculate total width of Children with jQuery</a>" which works, but only when I refresh the page. </p> <p>The jquery is in a separate file called horizontal.js and is being enqueued from the wordpress theme's functions.php file. The js gets the width of all the list items in the posts, adds them up and puts the width on the body of single post pages.</p> <pre><code>jQuery(document).ready(function($) { var width = 0; $('body.single .long li').each(function() { width += $(this).outerWidth( true ); }); $('body.single').css('width', width + 500); }); </code></pre> <p>I have been reading up on the difference between <code>(window).load</code> and <code>(document).ready</code> and it seems that what I have should be the best solution because I only want this function to execute once. I think the problem is where I am putting the js or it is interacting poorly with anther script or I need to delay the page loading until the script has fired, but I'm not sure how to check for these problems. </p> <p>The site is under development and the link is <a href="http://www.laurendarling.com/2011website/photography/afterparty/" rel="nofollow noreferrer">http://www.laurendarling.com/2011website/photography/afterparty/</a> username: guest, password: guest. If you click on the highlighted post title in the side nav the page reloads and js puts the width on the body tag allowing the horizontal layout. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload