Jump to content

jQuery width attribute error


longtone

Recommended Posts

I have a div #rotator, containing a number of images.

I am using this jQuery code to get the dimensions of the div and the first  image:

            //get size of div
            
            this.div_width =  $("#rotator ").width();
            this.div_height =  $("#rotator ").height();
            
           //get size of image
            
            this.img_width =  $("#rotator img:eq(0)").width();
            this.img_height =  $("#rotator img:eq(0)").height();

 

sometimes it works, sometimes the image dimensions come back completely wrong eg: 14 instead of 200

 

Any ideas why, and how to fix it?

 

Link to comment
Share on other sites

Thanks, I'll try that

 

I'm not sure that's the problem though, because I get the width error on the first image, which is loaded with the page, not the subsequent images loaded with JS

 

And surely the first image should be fully loaded before $(document).ready calls any functions?

 

I've got round it for now by making all the images the same size, but that does increase bandwidth and causes me unnecessary work...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.