Actually, it's a simple tweak to get that solved. The problem, as Joe
stated, is that once you declare widths greater than 320, it will
never resize down to that width because you've stated that an element
be "400px" (or whatever). Thus you'll never trigger the 320 width
you're testing for. You need to instead poll for a different width
value.
I ran into the same problem with my app. Just change this:
var orient = currentWidth == 320 ? "profile" : "landscape";
to this:
var orient = (currentWidth < 480) ? "profile" : "landscape";
So that instead of polling for the exact 320px, you're polling for a
width less than landscape width. This will then trigger when the
window width is less than 480px.
This gives you much more freedom to set widths, etc. Just don't set
anything at { width: 480px; }. Ever. Let the browser do that for you.
On Aug 4, 8:18 pm, Mr Junk <[EMAIL PROTECTED]> wrote:
> Hello,
> I'm trying to use the Javascript to change the orientation but it
> only works once or twice and then window.innerWidth doesn't change
> anymore.
>
> I have an alert in the outer loop of the checking function that shows
> that the value doesn't change when I rotate the iPhone.
>
> Any ideas?
>
> Thanks,
> ml
>
> var checktimer;
> var count = 0;
>
> if(document.images) {
> if(navigator.userAgent.indexOf("iPhone") !=
> -1) {
> iphone = 1;
> } else {
> iphone = 0;
> }
> }
>
> addEventListener("load", function( event ) {
> setTimeout( updateLayout, 0 );
> checkTimer = setInterval( updateLayout, 10000
> );
> }, false);
>
> var currentWidth = 0;
>
> function updateLayout() {
> alert( "Checking: " + window.innerWidth );
> if ( window.innerWidth != currentWidth ) {
> alert( "Updating layout: " +
> window.innerWidth );
> currentWidth = window.innerWidth;
> var orient = currentWidth == 320 ?
> "profile" : "landscape";
> document.body.setAttribute("orient",
> orient);
> }
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---