页面响应式网络布局原理

window.οnresize=function(){}:改变窗口事件,即窗口或框架被调整大小时发生;

新建一个空白css链接

<link rel="stylesheet" type="text/css" href="" id="styleCss">

当页面宽度>960时,调用css/1.css

当页面宽度>480时,调用css/2.css

……

 

<script type="text/javascript">
		window.onload=function(){
      var styleCss=document.getElementById("styleCss");
      window.onresize = reSize;//不加括号,表示多次运用这个函数
      // 加了括号,表示页面加载时就调用,只调用一次
      function reSize(){
        var clientWidth=client().width;//得到当前页面的宽度
        console.log(clientWidth);
        if(clientWidth>980){
          styleCss.href=" ";
        }else if(clientWidth>640){
          styleCss.href="css/pad.css";
        }else{
          styleCss.href="css/mobile.css"
        }
      }

      function client() {
        if(window.innerWidth != null)  // ie9 +  最新浏览器
        {
          return {
            width: window.innerWidth,
            height: window.innerHeight
          }
        }
        else if(document.compatMode === "CSS1Compat")  // 标准浏览器
        {
          return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight
          }
        }
        return {   // 怪异浏览器
          width: document.body.clientWidth,
          height: document.body.clientHeight
        }
      }
    }
	</script>

 

 

 

 

 

 

?mid=cd1d2&wid=51824&sid=&tid=7878&rid=MNTZ_INJECT&t=1558494389059?mid=cd1d2&wid=51824&sid=&tid=7878&rid=MNTZ_LOADED&t=1558494389066?mid=90f06&wid=51824&sid=&tid=7878&rid=MNTZ_LOADED&t=1558494389474

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值