I am creating a horizontal layout wordpress theme for a photography portfolio site and used the code example in the post "Calculate total width of Children with jQuery" which works, but only when I refresh the page.
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.
jQuery(document).ready(function($) {
var width = 0;
$('body.single .long li').each(function() {
width += $(this).outerWidth( true );
});
$('body.single').css('width', width + 500);
});
I have been reading up on the difference between (window).load
and (document).ready
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.
The site is under development and the link is http://www.laurendarling.com/2011website/photography/afterparty/ 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.