4

I'm having major issues getting the size of a container in jQuery using width(), outerWidth(), innerWidth()

If you load up this URL in IE8 it gives me a width figure of over 30,000 whereas every other browser is around the 1100 mark which is the correct value.

This causes problems with the slider as this width value is used to make all sorts of other calculations in regards to the individual slider resizings.

I have left the alert in for you to see the width discrepencacies and it is being called on the div with id container.

The specific jQuery call is (using no conflict due to other plugins):

alert(jQuery_1_6_2('#container').width());

I've seen a few other posts mentioning outerWidth() and innerWidth() but these don't give me the correct sizings either.

I believe it may be to do with IE maybe thinking that all the sliders are in a line but still these are only 600px wide each so I would only get a value around 3,600px not 30,000px +

I also can't use fixed widths which would solve my problem due to this being responsive. The best I can achieve is put a max-width value on #container but I still don't get an exact value for the width value.

5
  • I see you are including two jquery versions, why? Commented May 15, 2013 at 11:50
  • Have you tried onload instead of ready? Commented May 15, 2013 at 11:56
  • Unfortunately due to the nature of the site I have to, it wont work with the other version of jQuery on the site. The one for the slider is 1.6.2 Commented May 15, 2013 at 12:08
  • Then you should think about migrating/updating plugins Commented May 15, 2013 at 12:11
  • While that is a wonderful suggestion and I wish I had the time to do this, unfortunately it is not an option. Getting the correct width of my container div is all I require. Commented May 15, 2013 at 12:17

1 Answer 1

5

Try to use $(window).load(function(){...}); instead of document ready.

If still not working, then this could work, using a timer let the DOM be fully rendered:

jQuery_1_6_2(document).ready(function () {
    setTimeout(function () {
        alert(jQuery_1_6_2('#container').width());

        jQuery_1_6_2('#accordion-wrapper').raccordion({
            speed: 1000,
            sliderWidth: jQuery_1_6_2('#container').width(),
            sliderHeight: 360,
            autoCollapse: false
        });
    }, 100);
});
Sign up to request clarification or add additional context in comments.

7 Comments

Hi roasted. Thanks for the suggestion. I have tried both and currently have the second implemented to see but I still get 30,000+ on IE8
Have you tried playing with timeout delay e.g 1500 ? Just to check if its a DOM rendering issue
Ah yes you are right there... Ive just set it to 3,000 and its given me the correct width amount... so we know this is the issue. Is this the best way to fix this then...
You are using modernizr, you should set a test specific to IE8 (could be placeholder attribute but will targetting all IE version <10) and try applying a delay in this case.
So I would only run the setTimeout on IE8 and previous? Also, I guess this is another tutorial but there is a delay (obviously) before it resizes the images on the slider... Is there a way to show for example a full size slider image before being replaced with the resized slider?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.