横竖屏不同的情况来适配样式

来源:互联网 发布:淘宝怎么有流量 编辑:程序博客网 时间:2024/06/08 11:58

1.内联样式

2.外联样式

<!--竖屏-->
<linkrel="stylesheet"media="all and (orientation:portrait)"href="..."/>
<!--横屏-->
<linkrel="stylesheet"media="all and (orientation:landscape)"href="..."/>





3.js方法


JavaScript
1
2
3
4
5
6
7
8
9
10
var mql = window.matchMedia("(orientation: portrait)");
function onMatchMeidaChange(mql){
    if(mql.matches) {
        // 竖屏
    }else {
        // 横屏
    }
}
onMatchMeidaChange(mql);
mql.addListener(onMatchMeidaChange);

JavaScript
1
2
3
4
5
6
7
8
9
10
varmql=window.matchMedia("(orientation: portrait)");
functiononMatchMeidaChange(mql){
    if(mql.matches){
        // 竖屏
    }else{
        // 横屏
    }
}
onMatchMeidaChange(mql);
mql.addListener(onMatchMeidaChange);
0 0