What is the best method of re-rendering a web page on orientation change?

后端 未结 8 789
臣服心动
臣服心动 2020-11-28 06:43

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

8条回答
  •  情书的邮戳
    2020-11-28 07:15

    Used a method that causes a repaint and a reflow in a single javascript stack frame. Not keen on viewport specific answers as it is often a requirement for accessibility to keep pinch zooming etc.

    $(window).on('orientationchange', function() {
        document.body.style.display='none';
        document.body.offsetHeight; //cause a reflow
        document.body.style.display='block'; //cause a repaint
    }); 
    

    Or non-jquery equivalent

    window.addEventListener('orientationchange', function () {
        document.body.style.display='none';
        document.body.offsetHeight; //cause a reflow
        document.body.style.display='block'; //cause a repaint
    });
    

提交回复
热议问题