Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Jquery not running correctly on initial load
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Clearwater  
View profile  
 More options Nov 6, 8:24 am
From: Clearwater <pete.me...@googlemail.com>
Date: Fri, 6 Nov 2009 05:24:40 -0800 (PST)
Local: Fri, Nov 6 2009 8:24 am
Subject: Jquery not running correctly on initial load
Hi there, I have been using Jquery successfully for months now but
have found an interesting quirk, I have a gallery page (http://
www.philford.clearwaterdesign.co.uk/gallery/empty-beaches-project)
which cycles through all the images and calculates the correct margins
to use in order for the images to be flush with the left and right.

The odd thing is when the page is first loaded, or after a delete
cache, the script doesn't work right, it is calculating different
margins and messing the layout up. If you visit the page again, all
works fine.

I have changed the code quite a lot to see where the problem comes
from but still can't see the issue. My javascript is below, anyone
else come across this? Or know a solution?

Cheers
function adjustMargins(){
        // cycle through each image and total the image widths
        $(".catItem").each(function(i){
                var imgWidth = $(this).width();
                if(row1Widths + imgWidth +30 < pageWidth)
                {
                        row1Widths = row1Widths + imgWidth;
                        row1Num++;
                        $(this).addClass("row1")
                }
                else
                {
                        row2Widths = row2Widths + imgWidth;
                        row2Num++;
                        $(this).addClass("row2")
                }
        });
        // calculate the margins between the images
        row1Margin = (pageWidth - row1Widths) / (row1Num-1);
        row1Margin = Math.floor(row1Margin);
        row2Margin = (pageWidth - row2Widths) / (row2Num-1);
        row2Margin = Math.floor(row2Margin);
        $(".row1").each(function(i){
                $(this).css("margin-right", row1Margin+"px");
        });
        $(".row2").each(function(i){
                $(this).css("margin-right", row2Margin+"px");
        });
        $(".row1:last").css("margin-right", "0px");
        $(".row2:last").css("margin-right", "0px");

}

$(document).ready(function()
{
        row1Widths = 0;
        row2Widths = 0;
        row1Num = 0;
        row2Num = 0;
        pageWidth = $("#wrapper").css("width");
        pageWidth = pageWidth.replace("px", "");
        adjustMargins();


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google