2021-02-25 10:31发布
1.移动端具有window.orientation属性,
它返回视口相对于设备自然方向的角度。
可能的值是-90,0,90,和180,其中正值是顺时针,负值是逆时针的
-90
0
90
180,其中
function is_mobile_horizontal() {
function cb() {
if (window.orientation == undefined) {
return 'Not mobile';
}
if (window.orientation == 180 || window.orientation == 0) {
alert('竖屏')
if (window.orientation == 90 || window.orientation == -90) {
alert('横屏')
return;
cb();
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", cb, false);
2. Javascript提供的 MediaQueryList 对象接口判断是否横屏,使用如下语句
window.matchMedia("(orientation: portrait)")
最多设置5个标签!
1.移动端具有window.orientation属性,
它返回视口相对于设备自然方向的角度。
可能的值是
-90
,0
,90
,和180,其中
正值是顺时针,负值是逆时针的function is_mobile_horizontal() {
function cb() {
if (window.orientation == undefined) {
return 'Not mobile';
}
if (window.orientation == 180 || window.orientation == 0) {
alert('竖屏')
}
if (window.orientation == 90 || window.orientation == -90) {
alert('横屏')
}
return;
}
cb();
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", cb, false);
}
2. Javascript提供的 MediaQueryList 对象接口判断是否横屏,使用如下语句
一周热门 更多>