I have a fluid CSS layout which is rendering badly on an iphone when I change the orientation. (It looks fine when it is refreshed).
I am using the code below to ref
I had a similar problem and this is how I fixed it with jQuery.
In my case the styles were not changing correctly for my <nav>
element. I used a modified version of kidkaos77's code combined with $.get()
to only load a certain part of the page:
$(window).bind("resize",function() {
//on resize reload only nav & replace
$.get("index.php" + ' nav', function(data) {
$("nav").replaceWith($(data).find("nav"));
});
});
With this method you don't have to reload the entire page, but you would have to specify exactly which elements are being affected by the orientation change, which in your case it seems like you just need one div.
Try something like this:
$(function(){
changeOrientation(window.orientation == 0 ? "portrait" : "landscape");
$('body').bind('orientationchange',function(event){
changeOrientation(event.orientation)
});
function changeOrientation(ori){
$("#orientation").removeClass('portrait landscape');
$("#orientation").addClass(ori);
}
});