A-A+

用css媒体查询、js等实现手机、平板横竖屏判断

//此为平板竖屏

@media (min-width: 768px) and (orientation: portrait) {
body {
background-color:cyan;
}
}

 

function judgeDirection(){
if(window.orientation==180||window.orientation === 0){
alert("手机为竖屏!");
}
if(window.orientation==90||window.orientation==-90){
alert("手机为横屏!");
}
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", judgeDirection, false);
JS Bin on jsbin.com
未完

给我留言

Copyright © 花未全开月未圆 保留所有权利.   Theme  Ality

用户登录