如何区分横屏和竖屏, 在CSS中?
//竖屏
@media screen and (orientation:portrait) { div { background-color:red; }}
//横屏
@media screen and (orientation:landscape) { div { background-color:red; }}
如何区分横屏和竖屏, 在JS中?
function hengshuping(){
if(window.orientation==180||window.orientation==0){
console.log("竖屏状态!")
}
if(window.orientation==90||window.orientation==-90){
console.log("横屏状态!")
}
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false);