iPad/iPhone定向体类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iPad/iPhone定向体类相关的知识,希望对你有一定的参考价值。
This function will detect the orientation (portrait/landscape) of an ios device and set the body class to either portrait or landscape, as well as providing a global variable for use elsewhere in your JS.If you require multiple classes on your body tag, simply alter the code to use jQuery's addClass() and removeClass() functions.
function orient() { if (window.orientation == 0 || window.orientation == 180) { $("body").attr("class", "portrait"); orientation = 'portrait'; return false; } else if (window.orientation == 90 || window.orientation == -90) { $("body").attr("class", "landscape"); orientation = 'landscape'; return false; } } /* Call orientation function on page load */ $(function(){ orient(); }); /* Call orientation function on orientation change */ $(window).bind( 'orientationchange', function(e){ orient(); });
以上是关于iPad/iPhone定向体类的主要内容,如果未能解决你的问题,请参考以下文章
阻止除 iPhone、iPod 和 iPAD 以外的移动设备和台式机
screenShot代码不适用于ipad,适用于iphone
如何更改 iDevice (iPad/iPhone) 的方向?