if(window.innerWidth>window.innerHeight){ //横屏}else{ //竖屏}
或者
if(window.orientation==0){ //竖屏}else{ //横屏}
第一种方法在电脑和手机上都适用,第二种方法则只适用于手机