zoukankan      html  css  js  c++  java
  • js兼容性——获取当前浏览器窗口的宽高

    通过onresize事件

     1 window.onresize = function () {
     2     document.title = client().width + "    "+ client().height;
     3 }
     4 
     5 
     6  //获取屏幕可视区域的宽高
     7 function client(){
     8    if(window.innerHeight !== undefined){
     9        return {
    10             "width": window.innerWidth,
    11             "height": window.innerHeight
    12         }
    13     }else if(document.compatMode === "CSS1Compat"){
    14             return {
    15                 "width": document.documentElement.clientWidth,
    16                 "height": document.documentElement.clientHeight
    17             }
    18     }else{
    19        return {
    20             "width": document.body.clientWidth,
    21              "height": document.body.clientHeight
    22        }
    23     }
    24}
    25 
    26 二、获取浏览器宽度和高度-使用懒函数优化
    27 window.onresize = function() {                                
    28     document.title = client().width + "    " + client().height;
    29}
    30 
    31  //获取屏幕可视区域的宽高
    32    !function() {
    33        if(window.innerHeight !== undefined) {
    34             client = function() {
    35                 return {
    36                    "width": window.innerWidth,
    37                    "height": window.innerHeight
    38                 }
    39              }
    40        } else if(document.compatMode === "CSS1Compat") {
    41              client = function() {
    42                  return {
    43                     "width": document.documentElement.clientWidth,
    44                     "height": document.documentElement.clientHeight
    45                   }
    46               }
    47 
    48        } else {
    49              client = function() {
    50                  return {
    51                      "width": document.body.clientWidth,
    52                      "height": document.body.clientHeight
    53                   }
    54              }
    55 
    56         }
    57   }();
  • 相关阅读:
    【51nod】2590 持续讨伐
    【51nod】2589 快速讨伐
    【51nod】2606 Secondary Substring
    【LOJ】#3098. 「SNOI2019」纸牌
    【洛谷】P4202 [NOI2008]奥运物流
    【LOJ】#3103. 「JSOI2019」节日庆典
    【LOJ】#3102. 「JSOI2019」神经网络
    【洛谷】P5348 密码解锁
    【洛谷】P4883 mzf的考验
    【LOJ】#3101. 「JSOI2019」精准预测
  • 原文地址:https://www.cnblogs.com/web-wjg/p/7136899.html
Copyright © 2011-2022 走看看