I am working on my first responsive site, using 3 testing devices:
- htc desire 500 dual,
- iphone6, and
- my windows laptop.
And I am testing with various 'languages':
- css media queries
- jquery
- angular
When testing, angularjs gives strange results in the HTC:
@media screen and (max-width : 320px)
{ some_selector{ /* css that IS triggered */ }
}
jQuery(document).on( 'ready ',
function()
{ alert( jQuery( window ).innerWidth()) ;
}
) ; // RETURN: 320
my_app.controller( "my_controller" ,
function( $scope , $window )
{ alert( $window.innerWidth ) ;
}
) ; // RETURN: sometimes 980, sometimes 320, sometimes 192
EDIT
based on Jonathan's answer, I realize that this is just the same old problem of different browsers handling different window properties differently, especially during the document loading phase ... (which is basically the reason why everybody adopted jQuery, especially jQuery(document).ready(...)
handler)
The call to angular's my_app.controller(...)
is occurring before jquery's document ready phase, when the DOM is still going through initial setup phases (as you can see by the example below);
And the explanation of why HTC is different from iphone is almost certainly due to the fact that I am using firefox in the htc, and safari in the iphone ...
my_app
.controller( "my_controller" ,
function( $scope , $window )
{ alert( $window.innerWidth + "," + window.innerWidth + "," + window.document.documentElement.clientWidth ) ;
// returns 154,154,980
alert( $window.innerWidth + "," + window.innerWidth + "," + window.document.documentElement.clientWidth ) ;
// returns 320,320,320
}
) ;