移动设备横竖屏判断 CSS 、JS

横竖屏切换 页面布局 变化严重,使用媒体查询写两套css,- -

CSS

@media screen and (orientation: portrait) {
/* 竖屏 */
				
}
			
@media screen and (orientation: landscape) {
/* 横屏 */
				
}

JS

var d = window.matchMedia("(orientation: portrait)");
onMatchMeidaChange(d);
d.addListener(onMatchMeidaChange);
function onMatchMeidaChange(d) {
 if(d.matches) { // 竖屏
					
 } else { //横屏
				
 }
}
posted @ 2018-11-06 17:29  乂千  阅读(146)  评论(0编辑  收藏  举报